JavaSE8 base hashmap<integer,string> keySet values get a collection of all values for all keys

Source: Internet
Author: User
Tags api manual

Os:windows7 x64
Jdk:jdk-8u131-windows-x64
Ide:eclipse Oxygen Release (4.7.0)



Code

Package Jizuiku0;import java.util.collection;import java.util.hashmap;import java.util.set;/* * @version V17.09 * * public class mapdemo_110 {public static void main (string[] args) {hashmap<integer, string> HM = init (); SYSTEM.OUT.PRINTLN (HM);//Get all keys in set<integer> form set<integer> set = Hm.keyset (); for (Integer I:set) { System.out.println (i);} System.out.println ("-----------------");//Get all the values in collection<string> form collection<string> cs = Hm.values (); for (String Str:cs) {System.out.println (str);}} public static Hashmap<integer, string> init () {hashmap<integer, string> HM = new Hashmap<integer, STRING&G t; ();//The keys here are scrambled when added, but there is an interesting phenomenon in the output//To know the reason behind this phenomenon, it is necessary to understand the underlying code implementation//So-called convoluted, hm.put (1, "Beidou first yangming greedy wolf too star June"); Hm.put (2, "Beidou second Yin Jing giant door Yuan June"); Hm.put (5, "Beidou fifth Dan Yuanlian Zhen gang xing June"); Hm.put (6, "Beidou sixth Arctic Congus June"), Hm.put (7, "Beidou Seventh-day Army Guan Xingjun"); Hm.put (3, "Beidou third blessing Good LU save true star June") ; Hm.put (4, "Beidou Four Xuan the new star June"); Hm.put (8, "Beidou eighth left auxiliary hole star June"), Hm.put (9, "Beidou nineth right, Hidden light star June"); return HM;}


Result

Java is good, worth learning.
Learning Resources: API manual + Java source code + pure heart.

JavaSE8 base hashmap<integer,string> keySet values get a collection of all values for all keys

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.