Hi Here i am trying to sublist the items from list and print them 5 for each iteration. here in the following code it is printing same items every time
for(int i=0;i<4;i++)
{
List<Card> l=a.subList(a.size()-5, a.size());
System.out.println(l);
}
But here it is printing different items as if it is removing 5 from the list each time
for(int i=0;i<4;i++){
int deckSize = a.size();
List<Card> handView = a.subList(deckSize-5, deckSize);
ArrayList<Card> hand = new ArrayList<Card>(handView);
handView.clear();
System.out.println(hand);
}
what is the difference between the above two code snippets
handView.clear();doing that removal of items.