JAVA之对 ArrayList<Integer>排序

package yu;


import java.util.ArrayList;
import java.util.Collections;


public class Test1{
public static void main(String args[]) {

        ArrayList<Integer> list = new ArrayList<Integer>();
        //生成随机数
        for (int i = 0; i < 10; i++) {
            list.add((int) (Math.random() * 100));
        }
        //排序
        Collections.sort(list);
      
        //遍历
        for (Integer integer : list) {
    System.out.print(integer+" ");
}
    }
 
}
  
 
结果:2 27 37 37 46 50 53 65 88 88 
 

猜你喜欢

转载自blog.csdn.net/yu_m_k/article/details/80530187