Back
How can I Initialize an ArrayList through List.of()
If you are atleast using Java9:
import java.util.ArrayList;import java.util.List;ArrayList<String> friends = new ArrayList<>(List.of(“Virat”,”Rohit”));
import java.util.ArrayList;
import java.util.List;
ArrayList<String> friends = new ArrayList<>(List.of(“Virat”,”Rohit”));
Before Java 9, you need to use Arrays.asList()
ArrayList<String> friends = new ArrayList<>(Arrays.asList(“Virat”,”Rohit”));
Want to learn Java? Check out the core Java certification from Intellipaat.
31k questions
32.8k answers
501 comments
693 users