Sorting list

Discussion in 'Programming' started by MadMaxCookie, May 25, 2016.

Thread Status:
Not open for further replies.
  1. Hello so I sorting list in the java in Collection.reverse(list);

    I have this code
    Code (Java):
            List<Integer> list = new ArrayList<Integer>();
            list.add(5);
            list.add(6);
            list.add(10);
            list.add(20);
           
            Collections.reverse(list);
           
            for(Integer i : list) {
                System.out.println(i);
            }
    but its printing

    Code (Java):
    -20
    20
    10
    6
    5
     
  2. The method is called reverse. What did you think it would do. Use the sort method.

    Collection.sort(...)
     
  3. yes I already did sorry for not including it on this post got fixed already in another thread sorry for double posting.
     
Thread Status:
Not open for further replies.