Home>

Introduction to map:An object that maps keys to values.A map cannot contain duplicate keys;Each key can be mapped to at most one value.This interface replaces the dictionary class, which is completely an abstract class,Rather than an interface.

public interface map<k, v>

An object that maps keys to values.A map cannot contain duplicate keys;Each key can be mapped to at most one value.

import javautilhashmap;
 import javautilmap;
 public class test {
   public static void main (string [] args) {
     map map=new hashmap ();//Declaring a map
     mapput ("s", "haha");//put values ​​into map:map is stored in the form of key-value
     string str=mapget ("s") tostring ();//map get value with key "s"
     systemoutprintln (str);
   }
 }

Output:haha

Map key-value pairs. The values ​​are generally stored as objects.

Common methods in hashmap,put (object key, object value);associate the specified value with the specified key in this map

get (object key);//Find the corresponding value according to the key value.

Determine if the key exists:containskey (object key)

Determines whether the value exists:containsvalue (object value)

The characteristic of map is "key-value" (key-value) matching

import java.util.hashmap;
 import java.util.map;
 public class test {
   public static void main (string [] args) {
     map map=new hashmap ();
     string key="java";
     string key="java";
     map.put (key, "value of java");
     map.put (key, "value of java");
     system.out.println (map.get (key));
     system.out.println (map.get (key));
   }
 }

Output:

java1 value

java2 value

  • Previous "Problem with the SSL CA cert" solution appears in WordPress upgrade version and installation plugin
  • Next Jquery plugin pagination to achieve no refresh ajax pagination