Java集合框架API使用汇总(不断更新)

一维List创建与初始化

List<Integer>temp = new ArrayList<Integer>();
//或 List<Integer>temp = new ArrayList<>();

//用已经存在的list初始化 
List<Integer>copy = new ArrayList<Integer>(temp);

//增加与删除
temp.add(1);
temp.remove(temp.size()-1);

嵌套List

List<List<Integer>> ans = new ArrayList<List<Integer>>();
ans.add(temp);//二维list中加入一个一维list temp

Arrays.sort

edge是一个二维数组,以下写法是按照edge的第二个维度从大到小排序

Arrays.sort(edges, (a, b) -> (b[0] - a[0]));

猜你喜欢

转载自blog.csdn.net/weixin_39666736/article/details/108221511