Os:windows7 x64
Jdk:jdk-8u131-windows-x64
Ide:eclipse Oxygen Release (4.7.0)
Code
package jizuiku0;import java.util.hashmap;import Java.util.Map.Entry;import java.util.set;/* * @version V17.09 */public class mapdemo_1111 {public static void main (string[] args) {Hashmap<integer , string> HM = init (); SYSTEM.OUT.PRINTLN (HM);//Gets all the key-value pairs of the object's collection Set<entry<integer, string>> smeis= hm.entryset ();//Traversal key-value pairs Collection of objects for (Entry<integer, string> Entry:smeis) {//Key value Syste M.out.println (Entry.getkey () + ":" +entry.getvalue ());}} 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: Itcast and Itheima Video library. If you have public resources, can share to me, with your resources to learn also can.
Blog post is to watch the video, into thinking written. It's good that the teacher speaks well. Blog bad, is to give the most bitter not serious.
JavaSE8 base hashmap<integer,string> entryset traversal key-value pair collection