Created
April 7, 2017 09:58
-
-
Save ramadani/9b10017402b51c1b9c6a72c0842ec6fd to your computer and use it in GitHub Desktop.
Revisions
-
ramadani created this gist
Apr 7, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ public void case13() { ArrayList<User> users = new ArrayList<User>(); users.add(new User(1, "Adimas Lutfi Wicaksono")); users.add(new User(2, "Salman Alfarisi")); users.add(new User(3, "Muhammad Sholeh")); ArrayList<User> usersDeleted = new ArrayList<User>(); usersDeleted.add(new User(2, "Salman Alfarisi")); usersDeleted.add(new User(3, "Muhammad Sholeh")); ArrayList<Integer> usersDeletedId = new ArrayList<Integer>(); for (User user: usersDeleted) { usersDeletedId.add(user.getId()); } ArrayList<User> userRemain = new ArrayList<User>(); for (User user: users) { if (!usersDeletedId.contains(user.getId())) { userRemain.add(user); } } System.out.println(userRemain.toString()); } private class User { private Integer id; private String name; private Integer gender = 1; public User(Integer id, String name) { this.id = id; this.name = name; } public User(Integer id, String name, Integer gender) { this.id = id; this.name = name; this.gender = gender; } public Integer getId() { return id; } public String getName() { return name; } public String getGender() { return gender == 1 ? "Male" : "Female"; } public String toString() { return "ID: " + getId() + " Name: " + getName() + " Gender: " + getGender() + "\n"; } }