I am pretty new to java, usually writing python code, so you can downvote me as much as you want if only it will help me with understanding.
Is there more less "javish" way to swap two neighborhood elements of user-input array?
Currently I have:
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<>();
System.out.println("Enter some numbers:");
while (in.hasNextInt()) {
list.add(in.nextInt());
}
System.out.println("ArrayList Before: "+ list);
Collections.swap(list, 0, 1);
System.out.println("ArrayList After: "+ list);
}
which changes only first and second ones, but what if I want to change also 3 and 4 as 4 and 3 and so on, is it possible to do it this way?