Initialise a list:
Immutable
List<String> people = Arrays.asList("me", "you");
Mutable
ArrayList<String> people = new ArrayList<>(Arrays.asList("me", "you"));
people = new ArrayList<>(Arrays.asList("me", "you"));or use the double brace initialization:
ArrayList<String>= new ArrayList<String>() {{ add("Me"); add("You"); }}people
No comments:
Post a Comment