Skip to content
Advertisement

declare multiple arraylists

is it possible to declare 2 array lists in the same line? e.g:

List<String> mm= new ArrayList<String>();
List<String> kk= new ArrayList<String>();

Is it then possible to do something like:

List<String> mm,kk= new ArrayList<String>();

Obviously, I get a compile error when I do the above, and was wondering how could one declare 2 lists in the same line.

Advertisement

Answer

If you want that, you should do:

List<String> list_1 = new ArrayList<String>(), list_2 = new ArrayList<String>();
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement