What I have is
public static LinkedList<Mp3> musicList;
...
if (musicList == null) {
musicList = new LinkedList<Mp3>();
}//create... this works
but if I have like 5 or more lists how can I do something like this:
Object[] ob = new Object[]{musicList,musicList2,...,musicList10};
for (int i = 0; i < ob.length; i++){
if (ob[i] == null) ob[i] = new LinkedList<Mp3>();
}
If I put it in first way it’s working; how can I put it in like in second snippet?
Changing the references in the array will not change the original references used to create the array.
The references in the array are a copy of what was in the initialization.
What you should do is get rid of the musicListN variables and only have an array, or better yet use a List.
Then use musicLists.get() to everywhere you would have used the older variables.