object - Value of HashMap inside a Hashmap in Java -


i have hashmap of students stores id, name , last name. created :

map<interger, hashmap<string,string>> students = new hashmap<>(); 

where second hashmap stores name , lastname. goal student in swing application, succeed in searching id because it's key of first hashmap, i'd use of them this:

enter image description here

so question : if want search name or last name, how can value of first hashmap , put in new hashmap ?

you can iterate on hashmap :

private int searchbyname(string s) {     for(map.entry<integer, hashmap<string, string>> entry : students.entryset()) {         hashmap student = entry.getvalue(); // hashmap containing first , lastname         if (student.containskey(s)) // if name match             return entry.getkey(); // return student id     }     return 0; // student not found } 

for lastname use containsvalue(s) instead of containskey(s)


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

node.js - Express and Redis - If session exists for this user, don't allow access -

excel - I can't get the attachement of the email PHP -