Program:
package com;
import java.util.ArrayList;
import java.util.Collections;
/**
*
* @author user
*/
public class SortingProgram {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ArrayList list=new ArrayList();
list.add(1);
list.add(7);
list.add(5);
System.out.println("Before sorting: "+list);
Collections.sort(list);
System.out.println("After sorting: "+list);
}
}
Output:
Before sorting: [1, 7, 5]
After sorting: [1, 5, 7]
package com;
import java.util.ArrayList;
import java.util.Collections;
/**
*
* @author user
*/
public class SortingProgram {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ArrayList list=new ArrayList();
list.add(1);
list.add(7);
list.add(5);
System.out.println("Before sorting: "+list);
Collections.sort(list);
System.out.println("After sorting: "+list);
}
}
Output:
Before sorting: [1, 7, 5]
After sorting: [1, 5, 7]
0 comments:
Post a Comment