9、[简答题] 【Collections工具类使用】 ArrayList集合中有如下内容: {33,11,77,55},使用Collections.sort()对ArrayList集合中的数据进行排序,并打印出排序后的结果。

package day_03_test;

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

//9、[简答题]
//【Collections工具类使用】
//ArrayList集合中有如下内容: {33,11,77,55},使用Collections.sort()对ArrayList集合中的数据进行排序,并打印出排序后的结果。
public class Demo09 {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(33);
        arrayList.add(11);
        arrayList.add(77);
        arrayList.add(55);
        Collections.sort(arrayList);
        System.out.println(arrayList);
        //使用foreach
        for (Integer i:arrayList
             ) {
            System.out.println(i);
        }
    }
}
posted @ 2022-04-01 14:49  不只是智能hello  阅读(73)  评论(0)    收藏  举报