Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hashmap inside a Arraylist  RSS feed

 
sai rama krishna
Ranch Hand
Posts: 530
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hI,

I have a hashmap which has username and password information.
Map mapDetail = new HashMap();
mapDetail.put("username",username);
mapDetail.put("password",password);
HashMap is embedded in a arraylist like below
List missingList = new ArrayList();
missingList.add(mapDetail);


I need to read the username and password information to send it to one other java program. How can I achieve it.Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sai rama krishna wrote:I have a hashmap which has username and password information.
...
I need to read the username and password information to send it to one other java program. How can I achieve it.

Well, first I'd ask: why are you putting it in a List? Surely there can only be one of these Maps? And if, not, how do you propose to find the correct one?

Winston
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sai rama krishna wrote:I have a hashmap which has username and password information...

Another thing: I'd definitely get used to putting types in your Map definitions, viz:
Map<String, String> mapDetail = new HashMap<String, String>();
and if you actually have a User type:
Map<User, String> mapDetail = new HashMap<User, String>();
might be even better.

Winston
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote: if you actually have a User type:
Map<User, String> mapDetail = new HashMap<User, String>();
might be even better.


If you have a User type then you can actually just use a List<User> with the username and password information in that User object.
 
Javin Paul
Ranch Hand
Posts: 297
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Certainly a User type is good option. create getUsername() and getPassword() on User type and store them in a List e.g.



Later if you need to add any other functionality e.g. UserId, UserContact etc you can easily do them using User type.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!