一、描述:给定比赛队伍:“1,2,3,4,5”
二、需求结果:1-2,1-3,1-3 …
三、实现原理:1.将给定队伍传放入2个list。2.遍历集合1,将该元素在集合2中移除,遍历的同时放入 map 3.最终的list
String str = "1,2,3,4";
List<HashMap<Integer, Integer>> list = new ArrayList<>();
List<HashMap<String, Integer>> listNum = new ArrayList<>();
List<Integer> list1 = Arrays.stream(Arrays.stream(str.split(",")).mapToInt(s -> Integer.parseInt(s)).toArray()).boxed().collect(Collectors.toList());
List<Integer> list2 = Arrays.stream(Arrays.stream(str.split(",")).mapToInt(s -> Integer.parseInt(s)).toArray()).boxed().collect(Collectors.toList());
int num=1;
HashMap<String, String> mapNum = new HashMap<>();
for (int i = 0; i < list1.size(); i++) {
list2.remove(list2.indexOf(list1.get(i)));
for (int j = 0; j < list2.size(); j++) {
if (!list2.get(j).equals(list1.get(i))) {
HashMap<Integer, Integer> map = new HashMap<>();
map.put(list1.get(i), list2.get(j));
list.add(map);
}
}
}
2.输出结果
for (HashMap<Integer, Integer> m : list) {
for (Map.Entry<Integer, Integer> map : m.entrySet()) {
System.out.println("key=" + map.getKey() + "value=" + map.getValue());
}
}