Java Map uses

Source: Internet
Author: User

One:

Map, he is composed of a set of double columns, namely: Key=value form.

1 Package test12;2 3Import java.util.*;4 5  Public classMap_demo {6      Public Static  voidMain (String...args) {7 Map_demo ();8     }9      Public Static  voidMap_demo () {TenMap<string,integer> per_info=NewHashmap<>(); OnePer_info.put ("Tom", A);//Set key Val APer_info.put ("Tom", A); -Per_info.put ("OK", A); -Set<string> Key=per_info.keyset ();//gets the collection of keys. Because key is unordered. theIterator<string> k_it=key.iterator (); -          while(K_it.hasnext ()) { -System. out. Print (K_it.next ()); -         } +     } -}

which

V put (K,V) inserts key, Val. The map method requires that key cannot be duplicated, but if the inserted key is duplicated, it will not be an error.

Set keyset () Gets the key collection for the map, noting that the type is set.

Where the Put method returns a value of V, the value that is overwritten. Only if the same key value is overwritten. If the newly inserted value is null.

1 Package test12;2 3Import java.util.*;4 5  Public classMap_demo {6      Public Static  voidMain (String...args) {7 Map_demo ();8     }9      Public Static  voidMap_demo () {TenMap<string,integer> per_info=NewHashmap<>(); OneInteger I=per_info.put ("Tom", A);//Set key Val AInteger J=per_info.put ("Tom", A); -Per_info.put ("OK", A); -System. out. Print (i); theSystem. out. Print (j); -Set<string> Key=per_info.keyset ();//gets the collection of keys. Because key is unordered. -Iterator<string> k_it=key.iterator (); -          while(K_it.hasnext ()) { +System. out. Print (K_it.next ()); -         } +     } A}

Java Map uses

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.