I got a hashmap of String and arraylist as value; When the values are:
<StringA: {element1,element2}, StrinbB: {null}>
The displaying of values (i.e. the ArrayList) always start with empty element. So it looks like:
{ , 1.element1 2.element2 }
Problems:
- Why first element is empty?
- Why there is no coma between two elements?
The function:
public String printTableNames(HashMap<String, ArrayList<String>> Map) {
HashMap<String, ArrayList<String>> map = Map;
String s="\n\t\t Tables: ";
Iterator<Entry<String, ArrayList<String>>> iter = map.entrySet().iterator();
s= s + " { ";
while (iter.hasNext()) {
Entry<String, ArrayList<String>> entry = iter.next();
List<String> l = new ArrayList<String>();
l = entry.getValue();
String temp="";
for (int i=1; i<=l.size(); i++){
temp= temp +" "+ Integer.toString(i)+"."+l.get(i-1);
}
s = s + temp;
if (iter.hasNext()) {
s=s+",";
}
else s=s+" }";
}
return s;
}