Reputation: 13248
Here are my two Arraylists and how do I add one to the other
private ArrayList<String> myStringList= new ArrayList<String>();
private ArrayList<String> newStringList= new ArrayList<String>();
I would like to add all the strings which are in myStringList
to newStringList
.
Can anyone help me with this ?
Upvotes: 0
Views: 2806
Reputation: 1969
try this.Hope it helps
1. myStringList.addAll(newStringList);
2. you can loop and add to other.
Upvotes: 0
Reputation: 201447
You can use the constructor which takes a collection like
private List<String> newStringList= new ArrayList<>(myStringList);
Or call List.addAll(Collection)
like
newStringList.addAll(myStringList);
Upvotes: 4
Reputation: 13248
Got the answer:
Here is the way:
myStringList.addAll(newStringList);
Upvotes: 0