arraylist - ArrrayList inside Hashmap in retrieving key values -


private static map<string, arraylist<string>> loadvalues = new hashmap<string,arraylist<string>>(); static arraylist details = new arraylist<string>(); 

i enter 2 set of values... say.. key:1 values: abc, c@c.com, 555 , key:2 values: xyz,x@z.com,765

i tried this.

system.out.println("enter user id:");         userid = in.next();         system.out.println("enter name:");         name = in.next();         details.add(name);         system.out.println("enter e-mail:");         email = in.next();         details.add(email);         system.out.println("enter contact number:");         contactno = in.next();        details.add(contactno);         loadvalues.put(userid, details); 

and used iterator print... when try print, prints like...

1: abc, c@c.com, 555 ,xyz,x@z.com,765  2:  abc, c@c.com, 555 ,xyz,x@z.com,765 

but, need print, 1: abc, c@c.com, 555 , 2: xyz,x@z.com,765 should do?

this because don't create new list 2 records. since details static, both records in map point same list.

static list = new arraylist(); a.add(foo); map.put(1, a); a.add(bar); map.put(2, a); map.get(1) == map.get(2) >> true 

you need :

list = filllist(); list b = filllist(); map.put(1, a); map.put(2, b); 

where filllist represents creating new instance of list , filling it.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -