How to sort ArrayList in ascending order with Java

1 Answer

0 votes
import java.util.List; 
import java.util.ArrayList;  
import java.util.Iterator; 
import java.util.Collections;  
 
public class Test {  
    public static void main(String[] args) {  
        List list = new ArrayList<>();  
         
        list.add(1);  
        list.add(4);  
        list.add(3);  
        list.add(7);  
        list.add(5);  
  
        Collections.sort(list); 
 
        Iterator i = list.iterator();
         
        while(i.hasNext()) {  
             System.out.println(i.next());  
        }  
    }  
}  
 
  
  
  
/*
run:
  
1
3
4
5
7
  
*/

 



answered Sep 28, 2019 by avibootz

Related questions

1 answer 179 views
1 answer 154 views
1 answer 167 views
2 answers 157 views
1 answer 119 views
3 answers 189 views
...