Suppose I have a lot of String Variables(100 for example):
String str1 = \"abc\";
String str2 = \"123\";
String str3 = \"aaa\";
....
String st
Use an array:
String[] strs = { "abc","123","zzz" };
for(int i = 0; i < strs.length; i++){
list.add(strs[i]); //something like this?
}
This idea is so popular that there's built-in methods to do it. For example:
list.addAll( Arrays.asList(strs) );
will add your array elements to an existing list. If you just want a list with only the array elements, you can do it on one line:
List list = Arrays.asList( strs );