Well the thing is I wanted to copy ArrayList lista and save it as listaKopia, the problem is as list is changing the copy is doing same.
Can anyone help me, and mybe tell me why it is a thing, please.
package pl.codegym.task.task07.task0718;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Sprawdzanie kolejności
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> lista = new ArrayList<>();
String temp = null;
for(int a = 0; a < 10; a++) {
lista.add(a, reader.readLine());
}
ArrayList<String> listaKopia = lista;
for(int i = 0; i < lista.size(); i++) {
for(int j = i + 1; j < lista.size() - 1; j++) {
if(lista.get(j).length() < lista.get(i).length()) {
temp = lista.get(j);
lista.set(j, lista.get(i));
lista.set(i, temp);
}
}
}
for(int a = 0; a < listaKopia.size(); a++) {
if(listaKopia.get(a).length() != lista.get(a).length()) {
System.out.println(a);
}
}
}
}