Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java Collections Framework interfaces map     - ADSL router to defend their own network security methods (Linux)

- Talk Packages (Linux)

- Two minutes thoroughly so that you understand Android Activity Lifecycle (Programming)

- REDO LOG records management (Database)

- Docker ecosystem security is gradually maturing (Server)

- Bad name two variables (Linux)

- Android Send HTTP POST requests (Programming)

- C ++ Replication Control: Assignment operators and destructors (Programming)

- Build ASP.NET 5 development environment in Ubuntu (Server)

- Linux ./configure --prefix command (Linux)

- Build ftp server under CentOS 6.5 (Server)

- Linux system started to learn: how to view the Linux thread of a process (Linux)

- Copy U disk files to the Linux system on a virtual machine (Linux)

- Linux crontab command format example (Linux)

- Android Custom View step (Programming)

- Android application simulates the phone keypad (Programming)

- Use source packages compiled and installed GCC5.1 in Mac OS X 10.10.3 (Linux)

- C ++ runtime environment built on CentOS 6.6 and Oracle database connection (Database)

- Fedora 23 How to install LAMP server (Server)

- Bubble Sort Algorithms (Programming)

 
         
  Java Collections Framework interfaces map
     
  Add Date : 2018-11-21      
         
         
         
  Java Collections Framework is used to store data, also known as collection classes

Located under the java.util package

Common interfaces and classes under java.util package

Map Collection and the interface is the root of the Java Collections Framework

List collection is an ordered collection of elements in the collection can be repeated to access elements of the collection can be accessed according to the index of the element.

Set sets are unordered collection of elements in the collection can not be repeated in the collection of elements based on the element itself can only be accessed (the collection of elements is not allowed to repeat the reasons).

Map collection Save Key-value element of form can only be accessed according to its value for each key element for access.

Map Interface

Map Collection interface is not inherited interface. Map interface for maintaining key / value pairs (key / value pairs). This interface describes the mapping never duplicate key values.

HashMap is one of the most commonly used Map, which according to data values stored HashCode key, its value can be obtained directly from the key with fast access speed.

HashMap allows a maximum of a record key is Null; allow more than one record is Null; HashMap does not support thread synchronization, that at any one time can have multiple threads simultaneously write HashMap;

It may result in inconsistent data. If you need to synchronize, you can use the Collections synchronizedMap method makes HashMap has the ability to synchronize.

TreeMap can only maintain order, and can be used for sorting

Map and Collection:
  Map Collection belong to exist side by side with the collections framework
  Map storage is the key to
  Map storage element using put method, Collection using the add method
  Map collection method is not directly remove elements, but first converted to Set collection, acquiring element iterative
  Map collection of the keys to ensure the uniqueness of the

Common methods:

Add: value associated with this map put (K key, V value) specified in the specified key
        putAll (Map < ? extends K ,? extends V > m) will be copied to this map all of the mappings from the specified map
 

import java.util.HashMap;
import java.util.Map;
  
/ **
 *
 * Map collection added
 *
 * /
public class MapDemo
{
    public static void main (String [] args)
    {
        Map < String, Integer > m = new HashMap < String, Integer > ();
          
        m.put ( "zhangsan", 19);
        m.put ( "lisi", 49);
        m.put ( "wangwu", 19);
        m.put ( "lisi", 20);
        m.put ( "hanmeimei", null);
          
        System.out.println (m);
    }
}

Delete: clear () Removes all of the mappings map

        remove (Object key) If there is a mapping between keys, it is removed from this map

import java.util.HashMap;
import java.util.Map;
  
/ **
 *
 * Map collection deletions
 *
 * /
public class MapDemo
{
    public static void main (String [] args)
    {
        Map < String, Integer > m = new HashMap < String, Integer > ();
          
        m.put ( "zhangsan", 19);
        m.put ( "lisi", 49);
        m.put ( "wangwu", 19);
        m.put ( "lisi", 20);
        m.put ( "hanmeimei", null);
        System.out.println (m);
          
        System.out.println (m.remove ( "wangwu"));
          
        m.clear ();
        System.out.println (m);
    }
}


Analyzing: containsValue (Object value) if this map maps one or more keys to the specified value, it returns true

        containsKey (Object key) if this map contains a mapping for the specified key Returns true

        isEmpty () if this map contains no key - value mappings Returns true

import java.util.HashMap;
import java.util.Map;
  
/ **
 *
 * Map collection of judgment
 *
 * /
public class MapDemo
{
    public static void main (String [] args)
    {
        Map < String, Integer > m = new HashMap < String, Integer > ();
          
        m.put ( "zhangsan", 19);
        m.put ( "lisi", 49);
        m.put ( "wangwu", 19);
        m.put ( "lisi", 20);
        m.put ( "hanmeimei", null);
        System.out.println (m);
          
        System.out.println (m.containsKey ( "lisi"));
        System.out.println (m.containsValue (20));
        System.out.println (m.isEmpty ());
    }
}


 Get: get (Object key) Returns the value of the specified key is mapped; if this map contains no mapping for the key, or null

        size () Returns the mapping of key - value mappings.

        values () Returns a collection view of the values contained in this map

        entrySet () Returns a set view of the mappings contained in this map.
        keySet () Returns the key view of the mappings contained in this map.

import java.util.HashMap;
import java.util.Map;
  
/ **
 *
 * Map Gets a collection
 *
 * /
public class MapDemo
{
    public static void main (String [] args)
    {
        Map < String, Integer > m = new HashMap < String, Integer > ();
          
        m.put ( "zhangsan", 19);
        m.put ( "lisi", 49);
        m.put ( "wangwu", 19);
        m.put ( "lisi", 20);
        m.put ( "hanmeimei", null);
        System.out.println (m);
          
        System.out.println (m.get ( "lisi"));
        System.out.println (m.size ());
        System.out.println (m.values ());
        System.out.println (m.entrySet ());
        zhangsan = 19, hanmeimei = null]
        System.out.println (m.keySet ());
    }
}

Two kinds of map collections taken by:
. 1 Set < k > keySet: the map is stored in all the key to Set collection. Because the set with an iterator. All can be iteratively remove all keys, in the get method. Obtaining a value corresponding to each key.
    Remove the principle Map collection: the map turn into a collection set collection. Taking out through the iterator.
. 2 Set < Map.Entry < k, v > > entrySet: mapping relationship will be credited to the map collection set collection, and data type of this relationship is: Map.Entry
    Entry Map is actually in a static internal interface.
    Defined inside because only with Map set, with key-value pairs, will have a mapping between keys. Relationship Map collection belonging to an internal thing. And the thing element in the direct access Map collection.
     
         
         
         
  More:      
 
- Source compiler install Nginx (Server)
- Btrfs file system creation and their characteristics in Linux (Linux)
- Servlet life cycle works (Programming)
- Linux Troubleshooting: How to save the status of the SSH session is closed (Linux)
- Snapshot DataGuard (Database)
- Linux (Ubuntu) How iptables port mapping (Server)
- Let your PHP 7 faster (GCC PGO) (Linux)
- Linux Firewall IPCop Profile (Linux)
- Oracle set and remove columns unavailable (Database)
- Ubuntu cut screen method (Linux)
- Linux three ways to set environment variables (Linux)
- MySQL remote connection settings (Database)
- Linux command ls (Linux)
- VMware11 virtual machine Ubuntu14.10 system partition sda1 disk expansion (Linux)
- Linux vi command list (Linux)
- Recent Consolidation Using Linux security module (Linux)
- 25 Git Usage Tips (Linux)
- Linux ACL permissions (Linux)
- Use Redis as time-series database: why and how (Database)
- Create your own YUM repository (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.