+ 3
I don't know how to solve this,help me please
Fill in the blanks to add three items to the list, sort it, and print 2. List<Integer> list = new ArrayList<Integer>(); list. (4); list.add(2); .add(1); Collections. (list); System.out.println(list.get( ));
6 Réponses
+ 11
add
list
sort
1
First two are hopefully self explanatory.
sort is a method you can use in Collections, it will sort the list into ascending order.
Since its now sorted in ascending order the values are:
{1, 2, 4}
2 is at the index of 1.
get(index) is what the method is expecting.
So, get(1)
+ 3
List<Integer> list = new ArrayList<Integer>();
list.add(4);
list.add(2);
list.add(1);
Collections.sort(list);
System.out.println(list.get(1));
+ 2
Here is the solution :
add
list
sort
1
+ 1
thanks,i've solved it by myself,but thanks anyway,we need explanation for those codes
0
Try this may help you
add
list
sort
1
0
add
list
sort
1