java.util 中的集合类包含 Java 中某些最常用的类。最常用的集合类是 List 和 Map。List 的具体实现包括 ArrayList 和 Vector,它们是可变大小的列表,比较适合构建、存储和操作任何类型对象元素列表。List 适用于按数值索引访问元素的情形。
Map 提供了一个更通用的元素存储方法。Map 集合类用于存储元素对(称作“键”和“值”),其中每个键映射到一个值。从概念上而言,您可以将 List 看作是具有数值键的 Map。而实际上,除了 List 和 Map 都在定义 java.util 中外,两者并没有直接的联系。本文将着重介绍核心 Java 发行套件中附带的 Map,同时还将介绍如何采用或实现更适用于您应用程序特定数据的专用 Map。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>测试map</title> </head> <style type="text/css"> </style> <script type="text/javascript"> /* * Map对象,实现Map功能 * size() 获取Map元素个数 * isEmpty() 判断Map是否为空 * clear() 删除Map所有元素 * put(key, value) 向Map中增加元素(key, value) * remove(key) 删除指定key的元素,成功返回true,失败返回false * get(key) 获取指定key的元素值value,失败返回null * element(index) 获取指定索引的元素(使用element.key,element.value获取key和value),失败返回null * containsKey(key) 判断Map中是否含有指定key的元素 * containsValue(value) 判断Map中是否含有指定value的元素 * keys() 获取Map中所有key的数组(array) * values() 获取Map中所有value的数组(array) * */ function Map(){ this.elements = new Array(); //获取Map元素个数 this.size = function() { return this.elements.length; }, //判断Map是否为空 this.isEmpty = function() { return (this.elements.length < 1); }, //删除Map所有元素 this.clear = function() { this.elements = new Array(); }, //向Map中增加元素(key, value) this.put = function(_key, _value) { if (this.containsKey(_key) == true) { if(this.containsValue(_value)){ if(this.remove(_key) == true){ this.elements.push( { key : _key, value : _value }); } }else{ this.elements.push( { key : _key, value : _value }); } } else { this.elements.push( { key : _key, value : _value }); } }, //删除指定key的元素,成功返回true,失败返回false this.remove = function(_key) { var bln = false; try { for (i = 0; i < this.elements.length; i++) { if (this.elements[i].key == _key){ this.elements.splice(i, 1); return true; } } }catch(e){ bln = false; } return bln; }, //获取指定key的元素值value,失败返回null this.get = function(_key) { try{ for (i = 0; i < this.elements.length; i++) { if (this.elements[i].key == _key) { return this.elements[i].value; } } }catch(e) { return null; } }, //获取指定索引的元素(使用element.key,element.value获取key和value),失败返回null this.element = function(_index) { if (_index < 0 || _index >= this.elements.length){ return null; } return this.elements[_index]; }, //判断Map中是否含有指定key的元素 this.containsKey = function(_key) { var bln = false; try { for (i = 0; i < this.elements.length; i++) { if (this.elements[i].key == _key){ bln = true; } } }catch(e) { bln = false; } return bln; }, //判断Map中是否含有指定value的元素 this.containsValue = function(_value) { var bln = false; try { for (i = 0; i < this.elements.length; i++) { if (this.elements[i].value == _value){ bln = true; } } }catch(e) { bln = false; } return bln; }, //获取Map中所有key的数组(array) this.keys = function() { var arr = new Array(); for (i = 0; i < this.elements.length; i++) { arr.push(this.elements[i].key); } return arr; }, //获取Map中所有value的数组(array) this.values = function() { var arr = new Array(); for (i = 0; i < this.elements.length; i++) { arr.push(this.elements[i].value); } return arr; }; } //测试map alert('测试map'); var map=new Map(); map.put(0,0); map.put(1,1); map.put(2,2); alert('map的大小为:'+map.size()); for(var i=0;i<map.size();i++){ alert('map的key'+i+'对应的value值为'+map.get(i)); } alert('获取map中不存在的键'+map.get('获取map中不存在的键')); alert('map中的所有键的长度'+map.keys().length); for(var i=0;i<map.keys().lenght;i++){ alert('map中的键值'+map.keys()[i]); } alert('map中的所有的value值的长度'+map.values().length); for(var i=0;i<map.values().length;i++){ alert('map中的value的值'+map.values()[i]); } alert('判断map中的值value是否存在3'+map.containsValue(3)); </script> <body> 测试map </body> </html>

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Python is more suitable for data science and machine learning, while JavaScript is more suitable for front-end and full-stack development. 1. Python is known for its concise syntax and rich library ecosystem, and is suitable for data analysis and web development. 2. JavaScript is the core of front-end development. Node.js supports server-side programming and is suitable for full-stack development.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools