We create a Set
as:
Set myset = new HashSet()
How do we create a List
in Java?
2021-6-3 anglehua
We create a Set
as:
Set myset = new HashSet()
How do we create a List
in Java?
List myList = new ArrayList();
or with generics (Java 7 or later)
List<MyType> myList = new ArrayList<>();
or with generics (Old java versions)
List<MyType> myList = new ArrayList<MyType>();
Additionally, if you want to create a list that has things in it (though it will be fixed size):
List<String> messages = Arrays.asList("Hello", "World!", "How", "Are", "You");