Question : More Compact Syntax For Creating ArrayLists?

Hi,

In one of junit tests, I need to make sure that a method is returning the correct ArrayList.  However, unlike arrays, which allow you to use literals, it's fairly cumbersome and unreadable to create ArrayLists.  Is there a way to improve the code below?

Thanks.
1:
2:
3:
4:
5:
6:
ArrayList<String> actual = MyClass.methodImTesting("some input");
ArrayList<String> expected = new ArrayList<String>();
expected.add("1");
expected.add("2");
expected.add("3");
assertEquals(expected, actual);

Answer : More Compact Syntax For Creating ArrayLists?

Well you could do
1:
ArrayList<String> expected = new ArrayList<String>(Arrays.asList(new String[] {"a", "b" }));
Random Solutions  
 
programming4us programming4us