• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Hashmap inside a Arraylist

 
Ranch Hand
Posts: 842
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic