-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserArrayList.java
More file actions
26 lines (18 loc) · 612 Bytes
/
UserArrayList.java
File metadata and controls
26 lines (18 loc) · 612 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package collection;
import java.util.ArrayList;
import java.util.List;
public class UserArrayList {
public static void main(String[] args) {
List<User> userList = new ArrayList<User>(); // or LinkedList
userList.add(new User(1, "User1"));
userList.add(new User(2, "User2"));
userList.add(new User(3, "User3"));
userList.add(new User(4, "User4"));
userList.add(new User(5, "User5"));
System.out.println("User at index 2: " + userList.get(2) + "\n");
userList.add(2, new User(10, "New USER"));
for (User user : userList) {
System.out.println(user);
}
}
}