简体   繁体   中英

Is there a way to list the values of an object saved on Hashmap

How to list the values present in the object saved in a hashmap

I'm trying to see if i can get a way to list the values i saved on a object, I'm storing in hashmap, but i don't know if it's possible to retrieve these values

HashMap<String, User> hashUser = new HashMap<String, User>();
hashUser.put(cont, new User(user, password));

hashUser.keySet().stream().forEach((x) -> {
            System.out.println(hashUser.??);
        });

basically my problem is the same as this guy Displaying object values which are stored in a HashMap well, it's kind of solved then

就像@Lutz Horn在评论中写道,您可以使用values()方法来检索哈希图的值。

hashUser.values().forEach(user -> System.out.println("Username: " + user.getUsername() + " Password: "  + user.getPassword()));

hashUser.values() returns a Collection of hashUser values.

Iterator userIterator = hashUser.values().iterator();

with Java 8 userIterator.forEachRemaining(System.out::println);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM