Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java Collections Framework interfaces map     - ORA-04091 and Compound Trigger (Oracle 11g) (Database)

- Command-line based tools for better alternatives (Linux)

- Android official recommendation: DialogFragment create dialog (Programming)

- gzip, bzip2, xz, tar, zip compression, archive Detailed (Linux)

- Linux process management related content (Linux)

- The method of installing software under Ubuntu Linux (Linux)

- Partition contrast manifestations under Windows and Linux (Linux)

- To delete the directory and all specified files under the Mac (Linux)

- Easy to install Ubuntu 15.04 and Ubuntu 15.04 GNOME on Wayland trial (Linux)

- How to update the ISPConfig 3 SSL Certificates (Server)

- How to Install Android Studio on Ubuntu 15.04 / CentOS7 (Linux)

- MySQL appears data too long for column 'name' at row 1 to solve (Database)

- Linux, MySQL root privilege escalation another method (Linux)

- MySQL5.7 JSON type using presentation (Database)

- How to install Bugzilla 4.4 on Ubuntu / CentOS 6.x (Linux)

- To install and deploy Java applications under CentOS 6.5 (Linux)

- awk variables (Linux)

- Asynchronous JavaScript loading (Programming)

- KVM add virtual disks (Linux)

- Linux variable learning experience (Linux)

 
         
  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:      
 
- Bad name two variables (Linux)
- Spring JDBC Comments (Programming)
- ORA-04091 and Compound Trigger (Oracle 11g) (Database)
- FFmpeg compiled with only H264 decoding library (Programming)
- Use mod_wsgi Django application deployment (Server)
- Oracle local user login authentication fails ORA-01031 insufficient privileges (Database)
- Construction Spark source and application development environment (Server)
- Those functions under Linux you do not know the df command (Linux)
- Volatile keyword in C language understanding (Programming)
- C ++ inline functions (Programming)
- Port Telnet command to detect the remote host is turned on (Linux)
- Binding multiple network cards in Linux using command nmcli (Linux)
- Common Linux System Troubleshooting (Linux)
- Network traffic monitoring ntopng (Linux)
- MySQL combination Git achieve differential backups can be used in the production environment (Database)
- How to fix apt-get update can not add a new CD-ROM error (Linux)
- Git uses a basic tutorial (Linux)
- What is Java EE (Programming)
- Hadoop 0.23 compile common errors (Server)
- Linux /var/spool/ insufficient clientmqueue space solutions (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.