While there are two excellent answers telling you how to do this, I feel that the other answer is not enough: in most cases, you should not do this at all.
Arrays are cumbersome, in most cases you better use the collection API .
With the help of collections you can add and remove elements, and for different functions there are specialized collections (index search, sorting, uniqueness, FIFO access, concurrency, etc.).
Although, of course, itβs important and important to know about arrays and their use, in most cases using Collections makes the API more manageable (therefore new libraries like Google Guava are unlikely to use arrays).
So, for your scenario, I would prefer a list of lists, and I would create it using Guava:
List<List<String>> listOfLists = Lists.newArrayList(); listOfLists.add(Lists.newArrayList("abc","def","ghi")); listOfLists.add(Lists.newArrayList("jkl","mno","pqr"));
Sean Patrick Floyd Jan 24 '11 at 11:14 2011-01-24 11:14
source share