If you're using Eclipse Collections (formerly GS Collections), you can use the makeString()
method.
List<String> ids = new ArrayList<String>();
ids.add("1");
ids.add("2");
ids.add("3");
ids.add("4");
Assert.assertEquals("1,2,3,4", ListAdapter.adapt(ids).makeString(","));
If you can convert your ArrayList
to a FastList
, you can get rid of the adapter.
Assert.assertEquals("1,2,3,4", FastList.newListWith(1, 2, 3, 4).makeString(","));
Note: I am a committer for Eclipse collections.