zoukankan      html  css  js  c++  java
  • java——基础数据类型——map集合操作

    import java.util.*;

    public class map

    {

        public static void main( String[] args )

        {

            //Map list = new HashMap();

            Map<Integer, String> map = new HashMap<>();

            map.put(1,"shen");

            map.put(2,"wei");

            System.out.println(map.size());

            System.out.println("==================================1");

            System.out.println(map);

            System.out.println("==================================2");

            System.out.println(map.get(1));

            System.out.println(map.get(2));

            System.out.println("==================================3");

            Boolean a = map.containsKey(1);  //此映射是否包含

            System.out.println(a);

            System.out.println("==================================4");

            Boolean b = map.containsKey(3);

            System.out.println(b);

            System.out.println("==================================5");

            map.remove(2);

            System.out.println(map.size());

            System.out.println(map);

            System.out.println("==================================6");

            Object  value = map.get(1);

            System.out.println(value);

            System.out.println("==================================7");

            Boolean c = map.containsValue("shen");   //是否包含指定值

            System.out.println(c);

            System.out.println("==================================8");

            Boolean d = map.isEmpty();            //判断是否为空

            System.out.println(d);

            System.out.println("==================================9");

            map.put(2,"wei");

            map.put(3,"wei");

            Set<Integer> key = map.keySet();   //获取map中所有的key值,

            System.out.println(key);

            System.out.println("==================================9______1");

            Collection<String> value4 = map.values();   //获取map中所有的value值,

            System.out.println(value4);

            System.out.println("==================================9______2");

            map.clear();      //清空

            Boolean e = map.isEmpty();

            System.out.println(e);

            System.out.println("==================================10");

        }

    }

    ==============================================================================================================================================================

    执行结果:

    2

    ==================================1

    {1=shen, 2=wei}

    ==================================2

    shen

    wei

    ==================================3

    true

    ==================================4

    false

    ==================================5

    1

    {1=shen}

    ==================================6

    shen

    ==================================7

    true

    ==================================8

    false

    ==================================9

    [1, 2, 3]

    ==================================9______1

    [shen, wei, wei]

    ==================================9______2

    true

    ==================================10

  • 相关阅读:
    学习进度(十一)
    学习进度(十)
    人月神话阅读笔记1
    SQL SUM() 函数
    SQL GROUP BY 语句
    SQL HAVING 子句
    SQL UCASE() 函数
    SQL LCASE() 函数
    SQL MID() 函数
    SQL LEN() 函数
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/14426805.html
Copyright © 2011-2022 走看看