日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java map大小_Java中HashMap的size()方法: HashMap.size() - Break易站

發布時間:2024/9/27 java 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java map大小_Java中HashMap的size()方法: HashMap.size() - Break易站 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Java中的HashMap

HashMap類的java.util.HashMap.size()方法用于獲取哈希映射HashMap中映射的大小,該映射引用Map中鍵值對或映射的數量。

句法:

Hash_Map.size()

參數:該方法不接受任何參數。

返回值:該方法返回映射的大小,這也表示映射中存在的鍵值對的數量。

下面的程序說明了java.util.HashMap.size()的工作原理

HashMap.size()程序1:將字符串值映射到整數鍵。

// Java code to illustrate the size() method

import java.util.*;

public class Hash_Map_Demo {

public static void main(String[] args)

{

// Creating an empty HashMap

HashMap hash_map = new HashMap();

// Mapping string values to int keys

hash_map.put(10, "Geeks");

hash_map.put(15, "4");

hash_map.put(20, "Geeks");

hash_map.put(25, "Welcomes");

hash_map.put(30, "You");

// Displaying the HashMap

System.out.println("Initial Mappings are: " + hash_map);

// Displaying the size of the map

System.out.println("The size of the map is " + hash_map.size());

}

}

輸出:

Initial Mappings are: {20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4}

The size of the map is 5

HashMap.size()程序2:將整數值映射到字符串鍵。

// Java code to illustrate the size() method

import java.util.*;

public class Hash_Map_Demo {

public static void main(String[] args)

{

// Creating an empty HashMap

HashMap hash_map = new HashMap();

// Mapping int values to string keys

hash_map.put("Geeks", 10);

hash_map.put("4", 15);

hash_map.put("Geeks", 20);

hash_map.put("Welcomes", 25);

hash_map.put("You", 30);

// Displaying the HashMap

System.out.println("Initial Mappings are: " + hash_map);

// Displaying the size of the map

System.out.println("The size of the map is " + hash_map.size());

}

}

輸出:

Initial Mappings are: {4=15, Geeks=20, You=30, Welcomes=25}

The size of the map is 4

注意:對于具有不同數據類型的變體和組合的任何類型的映射,都可以執行相同的操作。

總結

以上是生活随笔為你收集整理的java map大小_Java中HashMap的size()方法: HashMap.size() - Break易站的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。