N
news.amnet.net.au
Hi
I have some empty values that I get from a TreeMap which it seems I cannot
remove.
I have a TreeMap which holds a key and for each key an List with values - I
get the values from a bean.
I have concatenated several strings (using # as a separator) in each List
entry which I would like to make, in my jsp, into individual ArrayList
entries.
In my jsp:
TreeMap relationships = new TreeMap();
ArrayList mylist - new ArrayList();
relationships = mb.getAllRelationships(leftwardfile);
(where mb is a bean which populates the TreeMap with values).
Set keySet = relationships.keySet();
Iterator it = keySet.iterator();
while (it.hasNext()) {
StringTokenizer separatetokenizer = new StringTokenizer(next =
relationships.get(it.next()).toString(),"#",false);
String token = separatetokenizer.nextToken();
mylist.add(token);
}
The problem is that between each Iterator value (i.e between each tokenizing
event where relationships.get(it.next()).toString() contains something), the
arrayList puts an empty value in. The strange thing is that I cannot leave
it out i..e. I tried:
StringTokenizer separatetokenizer = new StringTokenizer(next =
relationships.get(it.next()).toString(),"#",false);
String token = separatetokenizer.nextToken();
if (!"".equals(token) || !"null".equals(token)) {
mylist.add(token);
}
But the empty value still goes in. The interesting thing is that it seems to
be an empty value in the TreeSet as this only happens between two values of
"next" (see above) that contain something.
My question is: how can I assure no empty values go into the arraylist
mylist? Someting unusual is happening and it must have something to do with
the TreeSet, but I am not sure what it is.
Any help will be most welcome.
Thanks
Hugo
I have some empty values that I get from a TreeMap which it seems I cannot
remove.
I have a TreeMap which holds a key and for each key an List with values - I
get the values from a bean.
I have concatenated several strings (using # as a separator) in each List
entry which I would like to make, in my jsp, into individual ArrayList
entries.
In my jsp:
TreeMap relationships = new TreeMap();
ArrayList mylist - new ArrayList();
relationships = mb.getAllRelationships(leftwardfile);
(where mb is a bean which populates the TreeMap with values).
Set keySet = relationships.keySet();
Iterator it = keySet.iterator();
while (it.hasNext()) {
StringTokenizer separatetokenizer = new StringTokenizer(next =
relationships.get(it.next()).toString(),"#",false);
String token = separatetokenizer.nextToken();
mylist.add(token);
}
The problem is that between each Iterator value (i.e between each tokenizing
event where relationships.get(it.next()).toString() contains something), the
arrayList puts an empty value in. The strange thing is that I cannot leave
it out i..e. I tried:
StringTokenizer separatetokenizer = new StringTokenizer(next =
relationships.get(it.next()).toString(),"#",false);
String token = separatetokenizer.nextToken();
if (!"".equals(token) || !"null".equals(token)) {
mylist.add(token);
}
But the empty value still goes in. The interesting thing is that it seems to
be an empty value in the TreeSet as this only happens between two values of
"next" (see above) that contain something.
My question is: how can I assure no empty values go into the arraylist
mylist? Someting unusual is happening and it must have something to do with
the TreeSet, but I am not sure what it is.
Any help will be most welcome.
Thanks
Hugo