I have two lists of Strings and two lists of objects. I need to copy the list of strings to the correspondence list of objects with specific values.public List<Name> retrieveCitiesAndCountries(){  List<String> list1 = new ArrayList<String>(); //list of cities  List<String> list2 = new ArrayList<String>(); //list of countries  list1 = retrieveListOfCities();  list2 = retrieveListOfCountries();  List<Name> namesList = new ArrayList<Names>();  return namesList;}Name classclass Name{  String name;  String attrib;  ..}I need to add both lists to namesList and add the respective attribs. For example, all cities should have City as their attribs and all countries should have Country as their attribs. for(int i=0;i<list1.size();i++){     Name name = new Name();             name.setName(list1.get(i));     name.setAttrib(City);     namesList.add(name);   }  for(int i=0;i<list2.size();i++){     Name name = new Name();             name.setName(list2.get(i));     name.setAttrib(Country);     namesList.add(name);   }I am wondering if there is any better way to do it.I use namesList to return in JSON format.@RequestMapping(value = /names)public @ResponseBody List<Name> retrieveCitiesAndCountries(){    List<Name> namesList = retrievalServ.retrieveCitiesAndCountries();    return namesList;}
Adding two different group of objects to a list of groups
java;spring