Java Learning 6

Source: Internet
Author: User
Tags set set

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

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.