2

I am getting an list as shown below

 List<String> tr = newdatamap.get("B1").getRef();
 List<String> tr2 = newdatamap.get("B1").getMS();

now as you can see that we have two arraylists but I want to store it contents into single a list itself. Something like that:

List<String> tr = newdatamap.get("B1").getTradeRef() + newdatamap.get("B1").getTMS();

but it is showing an error. Please advise how we can combine them into a single linked list.

Konstantin Yovkov
  • 59,030
  • 8
  • 92
  • 140

1 Answers1

3

If you want to produce a new List with the content of tr and tr2, then you can try with:

List<String> list = new ArrayList<>(){{ addAll(tr); addAll(tr2); }};

If you want to append t2 to tr, then you can do:

List<String> tr = newdatamap.get("B1").getRef().addAll(newdatamap.get("B1").getMS());
Konstantin Yovkov
  • 59,030
  • 8
  • 92
  • 140