I feel like this two line program should be expressible in one line but I can't get the {} array literal to work inside the asList call. Is there a way?
String[] a = {"Whiskey", "Tango", "Foxtrot"};
myList.addAll(Arrays.asList(a));
I feel like this two line program should be expressible in one line but I can't get the {} array literal to work inside the asList call. Is there a way?
String[] a = {"Whiskey", "Tango", "Foxtrot"};
myList.addAll(Arrays.asList(a));
Arrays.asList receives an ellipsis (T...), so you just don't need the array literal:
myList.addAll(Arrays.asList("Whiskey", "Tango", "Foxtrot"));
As I don't think you need string array here, you can use like that
List<String> x = new ArrayList<String>() {{add("Whiskey");add("Tango")add("Foxtrot");}};