Retrieve array inside a list as a Map value
Hi All,
I am trying to retrieve data from a map value. One of the map value is actually an array inside a list. I am able to get only the memory location rather than the values inside the array inside the list. Below is the code that I am working on. Can someone please help me
Code:
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections.*;
import org.apache.commons.collections.collection.*;
import org.apache.commons.collections.MultiMap;
import org.apache.commons.collections.MultiHashMap;
import org.apache.commons.collections.map.*;
public class Names {
public static void main(String args[])
{
List result = new LinkedList();
String[] vs= {"name1","name2"};
result.add(vs);
MultiMap map = new MultiHashMap( );
map.put("ONE","TEST");
map.put("ONE",1);
map.put("ONE", result);
/*Set set = map.entrySet();
Iterator it = set.iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
System.out.println(entry.getKey() + " : " + entry.getValue());
}*/
Set keySet = map.keySet( );
Iterator keyIterator = keySet.iterator();
while( keyIterator.hasNext( ) ) {
Object key = keyIterator.next( );
System.out.println( "Key: " + key);
Collection values = (Collection) map.get( key );
Iterator valuesIterator = values.iterator( );
while( valuesIterator.hasNext( ) ) {
System.out.println( "Value: " + valuesIterator.next( ));
}
}
}
}
The output that I get is
Code:
Key: ONE
Value: TEST
Value: 1
Value: [[Ljava.lang.String;@9304b1]
Output Expected
Code:
Key: ONE
Value: TEST
Value: 1
Value: name1
Value: name2
Thanks