Welcome all. I am making an App dictionary in which I need to create a List<String> (or ArrayList). To do this, I created the following code snippet (just an example):
List<String> tempSOLUTION = new ArrayList<String>(); String temp = "abc123"; tempSOLUTION.add(temp);
I also tried the following:
tempSOLUTION.add(new String(temp));
Both of them add an item to the list, but during debugging, I find that this array has 12 objects, which are as follows:
[abc123, null, null, null, null, null, null, null, null, null, null, null]
My problem is that I cannot have these null elements since this new list is the key in the HashableMap<String> , so any change will throw an exception since the key will NOT exist.
Screenshot from the list (tempSOLUTION) using the debugger: http://www.pabloarteaga.es/stackoverflow.jpg
How to add an item to the list without creating all these null items?
After searching, I found an answer on how to remove these null elements, namely:
tempSOLUTION.removeAll(Collections.singleton(null));
But this does not work for my purpose.
Thanks in advance.