Java Learning notes: Java Map collection

Source: Internet
Author: User

First, Introduction

Typically, a map is a data structure that consists of key-value pairs, and each key in the collection is unique.

Second, notes
/*** Map: interface. Not collection sub-class Key-value key value pair key unique cannot repeat * when the same key is used again to save the data will overwrite the value values of the previous key * * HashMap: The underlying is a hash table, key conforms to the hash table character * Treemap: Bottom The layer is a two-fork tree *@authorHutiger **/ Public classMapstudy { Public Static voidMain (string[] args) {myMap (); }     Public Static voidMyMap () {Map<string, object> map =NewHashmap<string, object>(); Map.put ("A", "Aa-aa"); Map.put ("B", "BB-BB"); Map.put ("C", "CC-CC"); Map.put ("D", "DD-DD"); //Get Method//System.out.println (Map.get ("a")); //How to traverse mapset<entry<string, object>> sets = Map.entryset ();//put the data in the map into set//iterator<entry<string, object>> itsiterator=sets.iterator (); //While (Itsiterator.hasnext ()) {//map.entry<string, object> Entry = (map.entry<string, object>)//Itsiterator//. Next (); // }         for(Entry<string, object>entry:sets) {System.out.println (Entry.getkey ()+ "= +" +Entry.getvalue ()); }                //set<string> keys = Map.keyset (); //For (String string:keys) {//System.out.println (Map.get (keys)); // }    }     Public Static voidTest () {//the total number of pages of data for a scene transfer the current page of datalist<user> list =NewArraylist<user>(); List.add (NewUser ("admin")); List.add (NewUser ("admin")); List.add (NewUser ("admin")); List.add (NewUser ("admin")); intPages=30; Map<string, object> map =NewHashmap<string, object>(); Map.put ("List", list); Map.put ("Page", pages); }    }

Java Learning notes: Java Map collection

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.