java登录页-视图界面

A Map stores data in key and value association. Both key and values are objects. The key must be unique but the values can be duplicate. Although Maps are a part of Collection Framework, they can not actually be called as collections because of some properties that they posses. However we can obtain a collection-view of maps.

映射将数据存储在键和值关联中。 键和值都是对象。 键必须是唯一的,但值可以重复。 尽管地图是集合框架的一部分,但由于它们具有某些属性,因此实际上不能将它们称为集合。 但是,我们可以获得地图的集合视图

It provides various classes: HashMap, TreeMap, LinkedHashMap for map implementation. All these classes implements Map interface to provide Map properties to the collection.

它提供了各种类: HashMap,TreeMap,LinkedHashMap用于地图实现。 所有这些类都实现Map接口,以向集合提供Map属性。

地图接口及其子接口 (Map Interface and its Subinterface )

Interface Description
Map Maps unique key to value.
Map.Entry Describe an element in key and value pair in a map. Entry is sub interface of Map.
NavigableMap Extends SortedMap to handle the retrienal of entries based on closest match searches
SortedMap Extends Map so that key are maintained in an ascending order.
接口 描述
地图 将唯一键映射到值。
地图条目 在映射的键和值对中描述一个元素。 条目是Map的子界面。
导航地图 扩展SortedMap以根据最接近的匹配搜索处理条目的检索
SortedMap 扩展Map,以便密钥按升序维护。

地图界面方法 (Map Interface Methods)

These are commonly used methods defined by Map interface

这些是Map接口定义的常用方法

  • boolean containsKey(Object k): returns true if map contain k as key. Otherwise false.

    boolean containsKey (Object k ):如果map包含k作为键,则返回true。 否则为假。

  • Object get(Object k) : returns values associated with the key k.

    Object get (Object k ):返回与键k关联的值。

  • Object put(Object k, Object v) : stores an entry in map.

    对象放置 (对象k ,对象v ):在地图中存储一个条目。

  • Object putAll(Map m) : put all entries from m in this map.

    Object putAll (Map m ):将m中的所有条目放入此映射中。

  • Set keySet() : returns Set that contains the key in a map.

    Set keySet ():返回包含映射中的键的Set

  • Set entrySet() : returns Set that contains the entries in a map.

    Set entrySet ():返回包含映射项的Set

HashMap类 (HashMap class)

  1. HashMap class extends AbstractMap and implements Map interface.

    HashMap类扩展AbstractMap并实现Map接口。

  2. It uses a hashtable to store the map. This allows the execution time of get() and put() to remain same.

    它使用哈希表存储地图。 这样可以使get()put()的执行时间保持不变。

  3. HashMap does not maintain order of its element.

    HashMap不维护其元素的顺序。

HashMap有四个构造函数。 (HashMap has four constructor.)

HashMap()
HashMap(Map< ? extends k, ? extends V> m)
HashMap(int capacity)
HashMap(int capacity, float fillratio)

HashMap示例 (HashMap Example)

Lets take an example to create hashmap and store values in key and value pair. Notice to insert elements, we used put() method because map uses put to insert element, not add() method that we used in list interface.

让我们以创建哈希图并将值存储在键和值对中为例。 注意插入元素,我们使用put()方法,因为map使用put插入元素,而不是我们在列表界面中使用的add()方法。

import java.util.*;class Demo
{public static void main(String args[]){HashMap< String,Integer> hm = new HashMap< String,Integer>();hm.put("a",100);hm.put("b",200);hm.put("c",300);hm.put("d",400);Set<Map.Entry<String,Integer>> st = hm.entrySet();  //returns Set viewfor(Map.Entry<String,Integer> me:st){System.out.print(me.getKey()+":");System.out.println(me.getValue());}}
}

a:100 b:200 c:300 d:400

a:100 b:200 c:300 d:400

TreeMap类 (TreeMap class)

  1. TreeMap class extends AbstractMap and implements NavigableMap interface.

    TreeMap类扩展AbstractMap并实现NavigableMap接口。

  2. It creates Map, stored in a tree structure.

    它创建存储在树结构中的Map。

  3. A TreeMap provides an efficient means of storing key/value pair in efficient order.

    TreeMap提供了一种以有效顺序存储键/值对的有效方法。

  4. It provides key/value pairs in sorted order and allows rapid retrieval.

    它按排序顺序提供键/值对,并允许快速检索。

例: (Example:)

In this example, we are creating treemap to store data. It uses tree to store data and data is always in sorted order. See the below example.

在此示例中,我们将创建树形图来存储数据。 它使用树来存储数据,并且数据始终按排序顺序。 请参见以下示例。

import java.util.*;class Demo
{public static void main(String args[]){TreeMap<String,Integer> tm = new TreeMap<String,Integer>();tm.put("a",100);tm.put("b",200);tm.put("c",300);tm.put("d",400);Set<Map.Entry<String,Integer>> st = tm.entrySet();for(Map.Entry<String,Integer> me:st){System.out.print(me.getKey()+":");System.out.println(me.getValue());}}
}

a:100 b:200 c:300 d:400

a:100 b:200 c:300 d:400

LinkedHashMap类 (LinkedHashMap class)

  1. LinkedHashMap extends HashMap class.

    LinkedHashMap扩展了HashMap类。

  2. It maintains a linked list of entries in map in order in which they are inserted.

    它按插入顺序维护映射中条目的链接列表。

  3. LinkedHashMap defines the following constructor

    LinkedHashMap定义以下构造函数

    LinkedHashMap()LinkedHashMap(Map< ? extends k, ? extends V> m)LinkedHashMap(int capacity)LinkedHashMap(int capacity, float fillratio)LinkedHashMap(int capacity, float fillratio, boolean order)
  4. It adds one new method removeEldestEntry(). This method is called by put() and putAll() By default this method does nothing.

    它添加了一个新方法removeEldestEntry() 。 该方法由put()putAll()调用。默认情况下,此方法不执行任何操作。

例: (Example:)

Here we are using linkedhashmap to store data. It stores data into insertion order and use linked-list internally. See the below example.

在这里,我们使用linkedhashmap存储数据。 它将数据存储到插入顺序中,并在内部使用链接列表。 请参见以下示例。

import java.util.*;class Demo
{public static void main(String args[]){LinkedHashMap<String,Integer> tm = new LinkedHashMap<String,Integer>();tm.put("a",100);tm.put("b",200);tm.put("c",300);tm.put("d",400);Set<Map.Entry<String,Integer>> st = tm.entrySet();for(Map.Entry<String,Integer> me:st){System.out.print(me.getKey()+":");System.out.println(me.getValue());}}
}

a:100 b:200 c:300 d:400

a:100 b:200 c:300 d:400

翻译自: https://www.studytonight.com/java/map-interface-in-java.php

java登录页-视图界面

java登录页-视图界面_地图界面-Java集合相关推荐

  1. Unity3D_最简单的开始界面_结束界面

    Unity3D_最简单的开始界面_结束界面 开始界面 结束界面 开始界面 1.创建一个新的场景 添加button 2.C#脚本 LoadingGame.cs using System.Collecti ...

  2. java制作一个应用程序_一个制作java小应用程序的全过程

    一个制作java小应用程序的全过程 一.安装java软件: 从网上下载jdk-7u25-windows-i586.exe,安装到C:\Program Files\Java\jdk1.7.0_25. 二 ...

  3. java 线程中创建线程_如何在Java 8中创建线程安全的ConcurrentHashSet?

    java 线程中创建线程 在JDK 8之前,还没有办法在Java中创建大型的线程安全的ConcurrentHashSet. java.util.concurrent包甚至没有一个名为Concurren ...

  4. java 面试题合集_撩课-Java面试题合辑1-50题

    1.简述JDK.JRE.JVM? 一.JDK JDK(Java Development Kit) 是整个JAVA的核心, 包括了Java运行环境(Java Runtime Envirnment), 一 ...

  5. java 发送短信 多通道_一种Java卡多通道临时对象管理方法与流程

    本发明涉及Java智能卡领域,具体涉及一种Java卡多通道临时对象管理方法. 背景技术: :JavaCard规范支持逻辑通道的概念,允许最多智能卡中的16个应用程序会话同时开启,每个逻辑通道一个会话. ...

  6. php和java的区别菜鸟教程_浅谈Java和PHP的主要区别

    当谈到PHP与Java的差异性问题时,更多的是回答初学者的一些疑问.对于刚接触IT的同学来说,他们需要做好对未来职业的选择.所以是选择PHP还是选择Java更有利于自身的技术特点和发展前景.所以在解决 ...

  7. java中io是什么_深入理解Java中的IO

    深入理解Java中的IO 转载自:http://blog.csdn.net/qq_25184739/article/details/51205186 本文的目录视图如下: Java IO概要 a.Ja ...

  8. 有谁转行学java成功了的吗_转行学习java靠谱吗?

    转行学Java靠谱吗?靠不靠谱主要还是看你自己是否想要学好Java技术,是否想要从事这方面的岗位工作,如果你已经有了这个决心,那么自然而然什么都不会问题.无论我们学Java是兴趣还是想要通过学好Jav ...

  9. java正则截取xml节点_实例讲述Java使用正则表达式截取重复出现的XML字符串功能...

    Java使用正则表达式截取重复出现的XML字符串功能示例 本文实例讲述了Java使用正则表达式截取重复出现的XML字符串功能.分享给大家供大家参考,具体如下: public static void m ...

最新文章

  1. 关于iOS的社会化分享方案总结
  2. 东北育才 数论专场第2场
  3. 【收藏】如何避免everything每次都重建索引
  4. 悲观锁和乐观锁和gap锁
  5. 华硕z170a如何开启m2_「科技犬」新品游戏本、翻转屏评测汇总:华硕微星荣耀戴尔,选谁...
  6. 封装DataList分页
  7. Django 现可在 Windows Azure 上使用
  8. oracle系统AP对应的凭证编号,AP主要账户及会计分录
  9. 好用的MARKDOWN编辑器一览
  10. oracle误删除数据之后的恢复方法
  11. 【工科数学分析】2021-10-01-工科数学分析叒复习(二)
  12. emmagee 性能工具梳理
  13. 记Dorado7学习(5)
  14. java微博情感倾向性分析_基于微博的情感倾向性分析方法研究
  15. 完全拷贝的一份,程序员阅读书单
  16. Mac用Pycharm安装mediapipe报错ERROR: Could not find a version that satisfies the requirement mediapipe
  17. 小白学Docker(四) docker配置阿里云国内镜像加速器
  18. springboot接收多对象_SpringBoot Controller 中使用多个@RequestBody的正确姿势
  19. nowcoder15162 小H的询问
  20. html输入QQ自动获取QQ头像,我在开发web版使用第三方QQ登录网站的时候,发现引入的QQ头像登录(如下图)很戳,我想问一下这个样式怎么调?...

热门文章

  1. 一些简单的java,c程序
  2. 【正点原子FPGA连载】 第四章Vivado软件的安装和使用 摘自【正点原子】DFZU2EG/4EV MPSoC 之FPGA开发指南V1.0
  3. Jenkins+Pipeline流水线+Docker实现自动化CI/CD发布Java项目
  4. Proteus中如何实现按一次键使得74LS161计数器中数值加一并且显示在数码管上
  5. 仿百度壁纸client(五)——实现搜索动画GestureDetector手势识别,动态更新搜索keyword...
  6. myqr库制作二维码
  7. JasperReports+iReport在eclipse中的使用
  8. 一个适合初学者的C++推箱子小游戏
  9. HADAMARD不等式的证明
  10. 2012年中国城市GDP初步排行