java treemap_Java TreeMap size()方法與示例

java treemap

TreeMap類的size()方法 (TreeMap Class size() method)

  • size() method is available in java.util package.

    size()方法在java.util包中可用。

  • size() method is used to return the size of this TreeMap or in other words, we can say it returns the number of key-value pairs that exist in this TreeMap.

    size()方法用于返回此TreeMap的大小,換句話說,我們可以說它返回此TreeMap中存在的鍵/值對的數量。

  • size() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    size()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • size() method does not throw an exception at the time of returning size.

    返回size時, size()方法不會引發異常。

Syntax:

句法:

    public int size();

Parameter(s):

參數:

  • It does not accept any parameter.

    它不接受任何參數。

Return value:

返回值:

The return type of the method is int, it returns the number of existing key-value pairs in this TreeMap.

方法的返回類型為int ,它返回此TreeMap中現有的鍵值對的數量。

Example:

例:

// Java program to demonstrate the example 
// of int size() method of TreeMap 
import java.util.*;
public class SizeOfTreeMap {
public static void main(String[] args) {
// Instantiates TreeMap
TreeMap < Integer, String > tm = new TreeMap < Integer, String > ();
// By using put() method is
// to put the key-value pairs in
// treemap tm
tm.put(1, "C");
tm.put(4, "C++");
tm.put(3, "Java");
tm.put(2, "Php");
// Display TreeMap tm
System.out.println("tm: " + tm);
// By using size() method is to 
// return the size of this TreeMap
int size = tm.size();
// Display size of TreeMap tm
System.out.println("tm.size(): " + size);
}
}

Output

輸出量

tm: {1=C, 2=Php, 3=Java, 4=C++}
tm.size(): 4

翻譯自: https://www.includehelp.com/java/treemap-size-method-with-example.aspx

java treemap

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377933.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377933.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377933.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

LeetCode 98. 驗證二叉搜索樹 思考分析

題目 給定一個二叉樹&#xff0c;判斷其是否是一個有效的二叉搜索樹。 假設一個二叉搜索樹具有如下特征&#xff1a; 節點的左子樹只包含小于當前節點的數。 節點的右子樹只包含大于當前節點的數。 所有左子樹和右子樹自身必須也是二叉搜索樹。 1、利用BST性質&#xff1a;中序…

二、VC++環境的安裝

一、打開PyCharm 在Terminal中激活pytorch環境&#xff0c;conda activate pytorch 安裝pycocotools工具&#xff0c;pip install pycocotools 二、報錯需安裝VC 進入官網 安裝完成之后重啟電腦 三、再次安裝pycocotools 打開Pycharm&#xff0c;安裝pycocotools工具&am…

Android 網絡狀態的監控

1 http://www.cnblogs.com/qingblog/archive/2012/07/19/2598983.html 2 轉載于:https://www.cnblogs.com/bavariama/p/3268450.html

深入淺出jQuery——jQuery歷史

Dean Edwards編寫的Packer&#xff1a;http://dean.edwards.name/packer/轉載于:https://www.cnblogs.com/mingle/archive/2011/12/01/2271155.html

java enummap_Java EnumMap size()方法與示例

java enummapEnumMap類的size()方法 (EnumMap Class size() method) size() method is available in java.util package. size()方法在java.util包中可用。 size() method is used to return the size of this enum map (i.e. it returns the number of key-value pairs exists…

LeetCode 530. 二叉搜索樹的最小絕對差 思考分析

目錄題目思路1&#xff1a;遞歸遍歷得到result數組(單調遞增)&#xff0c;然后對數組進行前后差分&#xff0c;取最小值思路2&#xff1a;不用數組&#xff0c;進行優化思路3、回顧迭代法求解題目 給你一棵所有節點為非負值的二叉搜索樹&#xff0c;請你計算樹中任意兩節點的差…

一、線性回歸

一、在有監督學習中主要包括兩大類問題 分類問題&#xff1a;你去銀行貸款借錢&#xff0c;人家銀行會不會借給你&#xff1f;當然只有兩種答案&#xff1a;會、不會 回歸問題&#xff1a;人家銀行能借給你多少錢&#xff1f;是一個具體的值 舉個例子&#xff1a;假如你去銀行…

8-18-Exercise

8-18-小練 A.HDU 1172 猜數字 采用枚舉~【赤果果的暴力~】 代碼&#xff1a; 1 #include <iostream>2 #include <cstdio>3 #include <cstring>4 using namespace std;5 6 int x[111],y[111],s,ss,vis[4],dis[4];7 char a[111][5];8 9 void find(int b,int …

【轉】Windows下搭建object-c

Windows下搭建object-c 2011-07-15 22:18 272人閱讀 評論(0) 收藏 舉報 近打算針對iPhone、iPod touch和iPad開發一些應用&#xff0c;所以&#xff0c;需要開始學習Objective C&#xff08;蘋果推出的類似C語言的開發語言&#xff09;。由于蘋果的自我封閉的產業鏈發展模式&am…

java reader_Java Reader reset()方法與示例

java reader讀取器類的reset()方法 (Reader Class reset() method) reset() method is available in java.io package. reset()方法在java.io包中可用。 reset() method is used to reset this stream to the mark set by mark() method most recently. reset()方法用于將此流重…

leetcode 501. 二叉搜索樹中的眾數 思考分析

目錄題目1、不考慮BTS性質&#xff0c;直接尋找眾數集合&#xff08;利用map&#xff09;2、考慮BTS的中序遍歷結果性質題目 給定一個有相同值的二叉搜索樹&#xff08;BST&#xff09;&#xff0c;找出 BST 中的所有眾數&#xff08;出現頻率最高的元素&#xff09;。 假定 BS…

二、模型評估方法

IDE為Jupyter Notebook scikit-learn官網 scikit-learn是一個專門用于機器學習的工具包 運用到啥函數不知道咋使用&#xff1f;戳它–>scikit-learn工具包的API文檔 不知道用啥模板&#xff1f;戳它–>scikit-learn樣例模型 功能翻譯Classification分類Regression回歸Cl…

union

關鍵字 1. 共用體聲明和共用體變量定義共用體(參考“共用體”百科詞條)是一種特殊形式的變量&#xff0c;使用關鍵字union來定義共用體(有些人也叫"聯合")聲明和共用體變量定義與結構體十分相似。其形式為:union 共用體名{數據類型 成員名;數據類型 成員名;...} 變量…

SEL

Object-C 中的Selector 概念 Andrew Huang <bluedrum163.com> 轉載請注明作者和聯絡方式 在iphone程序中會大量看到selector這樣的用法。<<iphone開發基礎>花了很大一個篇幅來解析這個語法&#xff0c;但是不知 是翻譯問題&#xff0c;還是解釋過細&#xff0c…

Java Calendar add()方法與示例

日歷類的add()方法 (Calendar Class add() method) add() method is available in java.util package. add()方法在java.util包中可用。 add() method is used to perform add or subtract the given amount of time to the given cal_fi (calendar field). add()方法用于對指定…

三、線性回歸實驗分析

所有代碼塊都是在Jupyter Notebook下進行調試運行&#xff0c;前后之間都相互關聯。 文中所有代碼塊所涉及到的函數里面的詳細參數均可通過scikit-learn官網API文檔進行查閱&#xff0c;這里我只寫下每行代碼所實現的功能&#xff0c;參數的調整讀者可以多進行試驗調試。多動手…

leetcode 236. 二叉樹的最近公共祖先 思考分析

目錄題目思考分析改進本文章代碼思路來源于公眾號【代碼隨想錄】題目 給定一個二叉樹, 找到該樹中兩個指定節點的最近公共祖先。 百度百科中最近公共祖先的定義為&#xff1a;“對于有根樹 T 的兩個結點 p、q&#xff0c;最近公共祖先表示為一個結點 x&#xff0c;滿足 x 是 p、…

輕輕松松給PCB板添加LOGO

在 PCB 圖中放置漢字或圖形的方法&#xff1a;A、文字——> 圖片——> PCB 圖——> 復制到自己作品中B、圖片——> PCB 圖——> 復制到自己作品中1、首先準備好“BMP”格式的圖片&#xff0c;在圖片中依靠顏色分辨圖層&#xff0c;所以最好準備“單色黑白”圖。…

java bitset_Java BitSet clone()方法及示例

java bitsetBitSet類clone()方法 (BitSet Class clone() method) clone() method is available in java.util package. clone()方法在java.util包中可用。 clone() method is used to clone this Bitset or in other words, this method is used to create a Bitset that is si…

小技巧

//屏蔽下拉框的某一個選項 <disabled"disable">... 1 <html>2 <body>3 4 <select>5 <option>Volvo</option>6 <option>Saab</option>7 <option disabled"disabled">Mercedes</option>…