Код: Выделить всё
[5, 3, 8, 0, 1] --> [1, 3, 8, 0, 5]
Код: Выделить всё
public static void main(String[] args) {
int[] array = new int[]{ 5, 3, 1, 8, 0 };
int j = 0;
List listInt = Arrays.stream(array).filter(x -> x%2 != 0).sorted().boxed().collect(Collectors.toList());
int [] res = Arrays.asList(array).stream().mapToInt(x -> x%2 == 0 ? x : listInt.get(++j)).collect(Collectors.toList()).toArray();
}
Код: Выделить всё
Main.java:21: error: ')' expected
int [] res = Arrays.asList(array).stream().mapToInt((x[0]) -> x[0]%2 == 0 ? x[0] : listInt.get(++j)).collect(Collectors.toList()).toArray();
^
Main.java:21: error: not a statement
int [] res = Arrays.asList(array).stream().mapToInt((x[0]) -> x[0]%2 == 0 ? x[0] : listInt.get(++j)).collect(Collectors.toList()).toArray();
^
Main.java:21: error: ';' expected
int [] res = Arrays.asList(array).stream().mapToInt((x[0]) -> x[0]%2 == 0 ? x[0] : listInt.get(++j)).collect(Collectors.toList()).toArray();
^
3 errors
Подробнее здесь: https://stackoverflow.com/questions/721 ... ing-maptoi
Мобильная версия