1、最新做了一个经纬度相减获取最大距离的一个需求需要用到两两组合 因为用的是Set
public static Set printArrayCom() {
Set sets = new HashSet<>();
sets.add("123@456");
sets.add("111@222");
sets.add("666@888");
sets.add("777@222");
sets.add("asd@sdss");
sets.add("asd1@sdss2");
Set set = new HashSet();
String[] array = sets.toArray(new String[sets.size()]);
for (int i = 0; i < array.length; i++) {
for (int j = i + 1; j < array.length; j++) {
String[] comStr = new String[2];
comStr[0] = array[i];
comStr[1] = array[j];
if (!set.contains(comStr)) {
set.add(comStr);
}
}
}
return set;
}
public static void main(String[] args) throws Exception {
Set re = printArrayCom();
System.out.println(re.size());
Iterator it = re.iterator();
while (it.hasNext()) {
String arr[] = (String[]) it.next();
System.out.println(arr[0] + " ," + arr[1]);
}
}
原创在评论区:五个数两两组合怎么实现-CSDN论坛



