Using the iterator, I want to add array to another array list. but after the elements of the first list are added to the second list, the elements of the previous list are crushed. How do I prevent this?
GelirList firsList = new GelirList();
List(GelirList) finalList = new ArrayList<>;
Iterator<DvzGelir> iterator = input.getGelirlist().iterator();
while(iterator.hasNext()){
DvzGelir exList = (DvzGelir) iterator.next()
firstList.setName(exList.getName());
firstList.setNumber(exList.getNumber());
finalList.add(firstList);
}
I expect the output of : {eren,123}, {ezel,234}, but the actual output is {eren,123}, {eren,123}