我需要对序列进行排序。我不能使用sorted()。这样的任务
List<Integer> integerList = new ArrayList<>(List.of(55,2,3,4,5,1,2)); integerList.stream().
42fyovps1#
public class StringName { public static String stringName(String stringName){
List<Integer> integerList = new ArrayList(); integerList.add(55); integerList.add(2); integerList.add(3); integerList.add(4); integerList.add(5); integerList.add(1); integerList.add(2); //a bubble sort in stream integerList.stream().forEach(a -> { integerList.forEach(b -> { Integer indexB = integerList.indexOf(b); if (indexB == integerList.size() - 1) { return; } if (b > integerList.get(indexB + 1)) { Integer temp = integerList.get(indexB); temp = b; integerList.set(indexB, integerList.get(indexB + 1)); integerList.set(indexB + 1, temp); } }); }); for (Integer integerPri : integerList) { System.out.println(integerPri); } }
}
1条答案
按热度按时间42fyovps1#
public class StringName { public static String stringName(String stringName){
}