public class day0318 {
public static void main(String[] args) {
boolean flag = true;
int j;
Integer[] num = {23, 234, 356, 23, 14, 1, 5, 47, 213, 47, 36, 68546, 2};
这个方法参见
https://www.programcreek.com/2013/04/how-to-convert-array-to-arraylist-in-java/
//转换为ArrayList
ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(num));
System.out.println(arr);
while (flag) {
flag = false;
for (int i = 0; i < arr.size() - 1; i++) {
j = i + 1;
if (j < arr.size() && arr.get(i) > arr.get(j)) {
int tem = arr.get(i);
arr.set(i, arr.get(j));
arr.set(j, tem);
flag = true;
}
}
}
System.out.println(arr);
}
}