Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

initializing list in java

// import java.util.*
//init as Arraylist
List a = new ArrayList();
//init as LinkedList
List b = new LinkedList();
//init as vector
List c = new Vector(); 
//init as stack
List d = new Stack(); 

//init with a type
List<Integer> list=new ArrayList<>();

//init with value
List<Integer> list=Arrays.asList(1, 2, 3);

//init with value
List<Integer> list=new ArrayList<>(Arrays.asList(1, 2, 3));

//init with value
List<Integer> list=new ArrayList<Integer>(){{
                        add(1);
                        add(2);
                        add(3);
                          }};

Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #initializing #list #java
ADD COMMENT
Topic
Name
9+6 =