java 方法 示例_Java Collectionsfrequency()方法與示例

java 方法 示例

集合類的frequency()方法 (Collections Class frequency() method)

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

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

  • frequency() method is used to return the frequency of the given Object (obj) to the given Collection (co) or in other words, this method is used to return the number of elements in the given collection which is same as the given Object (obj).

    frequency()方法用于將給定Object(obj)的頻率返回給定Collection(co),換句話說,該方法用于返回給定Collection中與給定Object相同的元素數(obj)。

  • frequency() method is a static method, so it is accessible with the class name and if we try to access the method with the class object then also we will not get an error.

    frequency()方法是一個靜態方法,因此可以使用類名進行訪問,如果嘗試使用類對象訪問該方法,那么也不會收到錯誤。

  • frequency() method may throw an exception at the time of returning frequency.

    frequency()方法在返回頻率時可能會引發異常。

    NullPointerException: This exception may throw when the given parameter Collection (co) if null exists.

    NullPointerException :如果給定參數Collection(co)存在null,則可能引發此異常。

Syntax:

句法:

    public static int frequency(Collection co, Object obj);

Parameter(s):

參數:

  • Collection co – represents the Collection object in which to calculate the frequency of the given Object (obj).

    Collection co –表示要在其中計算給定對象(obj)頻率的Collection對象。

  • Object obj – represents the object whose frequency is to be calculated.

    對象obj –表示要計算其頻率的對象。

Return value:

返回值:

The return type of this method is int, it returns the frequency of the given object with respect to the given collection.

此方法的返回類型為int ,它返回給定對象相對于給定集合的頻率。

Example:

例:

// Java program is to demonstrate the example
// of int frequency() of Collections
import java.util.*;
public class Frequency {
public static void main(String args[]) {
// Instantiate a LinkedList   
List link_l = new LinkedList();
// By using add() method is to
// add elements in linked list
link_l.add(10);
link_l.add(20);
link_l.add(30);
link_l.add(40);
link_l.add(50);
link_l.add(40);
link_l.add(30);
// Display LinkedList
System.out.println("link_l: " + link_l);
System.out.println();
// By using frequency() method is to
// return the object frequency of the
// given collection linked ist
int f1 = Collections.frequency(link_l, 40);
int f2 = Collections.frequency(link_l, 30);
// Display frequency
System.out.println("Collections.frequency(link_l,40): " + f1);
System.out.println("Collections.frequency(link_l,30): " + f2);
}
}

Output

輸出量

link_l: [10, 20, 30, 40, 50, 40, 30]Collections.frequency(link_l,40): 2
Collections.frequency(link_l,30): 2

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

java 方法 示例

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

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

相關文章

線性結構常規操作(四)

定義存儲結構(以單向鏈表為主) 對于鏈表的定義,通過結構體進行定義,包括兩部分,一是數據域,另一個就是指針,用于指向下一個節點。 1,創建鏈表 定義鏈表: struct nodesq{int data;//數據域&a…

ffplay分析 (暫停 / 播放處理)

《ffplay的數據結構分析》 《ffplay分析(從啟動到讀取線程的操作)》 《ffplay分析(視頻解碼線程的操作)》 《ffplay分析(音頻解碼線程的操作)》 《ffplay 分析(音頻從Frame(解碼后)隊列取數據到…

源碼 狀態機_[源碼閱讀] 阿里SOFA服務注冊中心MetaServer(1)

[源碼閱讀] 阿里SOFA服務注冊中心MetaServer(1)0x00 摘要0x01 服務注冊中心1.1 服務注冊中心簡介1.2 SOFARegistry 總體架構1.3 為什么要分層0x02 MetaServer2.1簡介2.2 問題0x03 代碼結構0x04 啟動運行4.1 集成部署4.2 獨立部署0x05 總體邏輯5.1 程序主體5.2 配置0x06 啟動6.1…

HttpService遠程校驗

今天學了下HttpService,和大家分享一下。HttpService是用來讀取遠程數據的一個對象,數據格式為XML。 我做了一個登陸校驗的功能,主要是通過HttpService將服務器端的用戶數據得到,然后在客戶端判斷輸入的用戶名和密碼是否存在。 主…

免費開源FTP Server軟件FileZilla Server

很多朋友在實際應用中都可能需要用到FTP Server類的軟件,這類軟件有很多,比較知名的有Serv-U、G6等,這里向大家介紹一下FileZilla Server,Windows平臺下一款不錯的FTP Server軟件,而且是免費的、開源的。 S…

Java BigDecimal floatValue()方法與示例

BigDecimal類floatValue()方法 (BigDecimal Class floatValue() method) floatValue() method is available in java.math package. floatValue()方法在java.math包中可用。 floatValue() method is used to convert a BigDecimal to a float value and when this BigDecimal m…

明明的隨機數(快排)

明明想在學校中請一些同學一起做一項問卷調查,為了實驗的客觀性,他先用計算機生成了N個1到1000之間的隨機整數(N≤100),對于其中重復的數字,只保留一個,把其余相同的數去掉,不同的數…

ffplay分析 (seek操作處理)

《ffplay的數據結構分析》 《ffplay分析(從啟動到讀取線程的操作)》 《ffplay分析(視頻解碼線程的操作)》 《ffplay分析(音頻解碼線程的操作)》 《ffplay 分析(音頻從Frame(解碼后)隊列取數據到…

android 代碼設置 鍵盤適應_硬核軟件,能在電腦上控制iPhone和Android手機

在電腦上控制手機大概已經不是什么新鮮操作,小米、華為都為自家手機和電腦的聯動推出了同屏操作之類的功能,此外也可以通過開源軟件Scrcpy來在Windows或者macOS上實現對安卓手機的控制,這些基本都只針對安卓手機。近期,奇客君發現…

網址出現error.aspx?aspxerrorpath=404.htm?aspxerrorpath=的原因及解決辦法轉

網址出現aspxerrorpath的問題描述 1.網頁打不開了,輸入網址后就提示error.aspx?aspxerrorpath/about-us.html,到底是什么原因啊? 2.ASP網站自定義了404錯誤頁,但訪問不存在的網址時網址錯誤頁后面總多出aspxerrorpath參數,怎么解…

ruby hash方法_Ruby中帶有示例的Hash.default(key = nil)方法

ruby hash方法Hash.default(key nil)方法 (Hash.default(keynil) Method) In this article, we will study about Hash.default(keynil) Method. The working of this method can be predicted with the help of its name but it is not as simple as it seems. Well, we will…

回文數、括號匹配(棧操作)

回文數 “xyzyx”是一個回文字符串,所謂回文字符串就是指正讀反讀均相同的字符序列,如“席主席”、“記書記”、“aha”和“ahaha”均是回文,但“ahah”不是回文。輸入一行字符(僅包含小寫英文字母a~z)請判斷這行字符…

ijkplayer 消息循環處理過程分析

ijkplayer 消息循環處理過程分析簡介一、消息隊列初始化1、 initWithContentURLString函數2、 ijkmp_ios_create函數3、 ijkmp_create函數二、消息隊列的消息循環處理函數啟動1、prepareToPlay函數2、ijkmp_prepare_async函數3、ijkmp_prepare_async_l函數4、ijkmp_msg_loop函數…

json解析對應的value為null_徒手擼一個JSON解析器

Java大聯盟致力于最高效的Java學習關注作者 | 田小波cnblogs.com/nullllun/p/8358146.html1、背景JSON(JavaScript Object Notation) 是一種輕量級的數據交換格式。相對于另一種數據交換格式 XML,JSON 有著諸多優點。比如易讀性更好,占用空間更少等。在 …

[一]設計模式初探

模式,顧名思義,就是做一種事情的方法歸納,就經驗來說,做什么事情有個好的方法來應對都是可以事半功倍的,在軟件開發中何謂好的模式? 我認為好的模式簡單來說就是保證你應對需求變化的時候不用做更多的代碼修改&#x…

Gentoo - ssh-agent配置

現在使用類似github這樣的service&#xff0c;一般來說都會配置ssh key認證。所以使用ssh-agent來管理私鑰就變的必要。在Gentoo下是這么配置的&#xff1a;- sudo emerge -avt keychain- 編輯.bashrc&#xff0c;加入keychain <private key 1 path> ... <private key…

java 方法 示例_Java ArrayDeque offerFirst()方法與示例

java 方法 示例ArrayDeque類offerFirst()方法 (ArrayDeque Class offerFirst() method) offerFirst() Method is available in java.lang package. offerFirst()方法在java.lang包中可用。 offerFirst() Method is used to add the given element at the front of this deque. …

平院Python習題

在讀寫文件之前&#xff0c;用于創建文件對象的函數是&#xff08; A &#xff09;。 A&#xff0e; open B&#xff0e; create C&#xff0e; file D&#xff0e;folder 解析&#xff1a; open(file, mode‘r’, buffering-1, encodingNone, errorsNone, newlineNone, close…

搭建srs服務器(rtmp)

搭建srs服務器&#xff08;rtmp&#xff09; 目錄:1、下載srs源碼&#xff08;從碼云上&#xff09;&#xff1a;2、 切換到srs.oschina&#xff1a;3、 這里使用3.0版本&#xff1a;4、 切換到trunk&#xff1a;5、 編譯&#xff1a;6、 啟動&#xff1a;7、查看日志輸出&…

MOSS信息管理策略定制(MOSS custom policies)

MOSS引入了信息管理策略&#xff0c;通過給文檔庫或列表附加一些策略可以實現一些自動化的功能&#xff0c;如自動給文檔打標簽&#xff0c;強制文檔的審核&#xff0c;啟用文檔的過期&#xff0c;甚至可以在用戶打印文檔時插入條形碼。難么&#xff0c;這么好用的功能是怎么實…