I haven't written a blog for a long time. Today, I've revisited the Java Foundation
(1) The elements in the Java map collection cannot be obtained directly from the enhanced for loop, but can be obtained by means of its methods keyset () and EntrySet () to get the set set.
(2) Learn the use of JUnit test class, add @test before the method. It is convenient to test which method, right-click Run as Junit test.
(3) Eclipse Some of the shortcut key learning.
Code FIX: Ctrl+1
Code copy: checked, ctrl+alt+ down arrow
Code movement: ALT + up and down keys
Guide Package: Ctrl+shift+o
View shortcut keys: ctrl+shift+l
Packagetest;ImportJava.util.HashMap;ImportJava.util.LinkedHashMap;ImportJava.util.Map;ImportJava.util.Map.Entry;Importorg.junit.Test; Public classHello {@Test Public voidTest () {System.out.println ("Hehe"); } @Test Public voidtest1 () {Map<String,String> map =NewHashmap<string,string>(); Map.put ("Hehe", "1"); Map.put ("Haha", "2"); Map.put ("Xixi", "3"); //with keyset for(String Key:map.keySet ()) {String Value=Map.get (key); SYSTEM.OUT.PRINTLN (Key+"="+value); } //with entry for(Entry<string, string>Entry:map.entrySet ()) {String key=Entry.getkey (); String value=Entry.getvalue (); SYSTEM.OUT.PRINTLN (Key+"="+value); }} @Test Public voidtest2 () {Map<String,String> map =NewLinkedhashmap<string,string>(); Data can be output in the order in which they are stored Map.put ("Hehe", "1"); Map.put ("Haha", "2"); Map.put ("Xixi", "3"); //with keyset for(String Key:map.keySet ()) {String Value=Map.get (key); SYSTEM.OUT.PRINTLN (Key+"="+value); } //with entry for(Entry<string, string>Entry:map.entrySet ()) {String key=Entry.getkey (); String value=Entry.getvalue (); SYSTEM.OUT.PRINTLN (Key+"="+value); } }}
Java Learning 6