Skip to content

Instantly share code, notes, and snippets.

@ramadani
Created April 7, 2017 09:10
Show Gist options
  • Save ramadani/ad1beccafcae14505d81f46b3d2f869c to your computer and use it in GitHub Desktop.
Save ramadani/ad1beccafcae14505d81f46b3d2f869c to your computer and use it in GitHub Desktop.
Javan Array Study Case 14
public void case14() {
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> usersNew = new ArrayList<User>();
usersNew.add(new User(4, "Yadi Cahyadi"));
usersNew.add(new User(5, "Maya Maulani"));
users.addAll(usersNew);
}
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";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment