+ 3
How to initialize a LinkedList object with elements when creating it.
There is some way to initialize a LinkedList object at the time of creating it other than this one.. LinkedList lst; List l = Arrays.asList(1,5,2,3,9); lst = new LinkedList(l); https://code.sololearn.com/cr799j68SGQ3/?ref=app
1 Resposta
+ 1
In Java, u can initialize a LinkedList object with elements directly by using double brace initialization. Here is an example:
LinkedList<Integer> lst = new LinkedList<Integer>() {{
add(1);
add(5);
add(2);
add(3);
add(9);
}};