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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

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

發(fā)布時(shí)間:2023/12/1 java 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 方法 示例_Java Collectionsfrequency()方法与示例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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相同的元素?cái)?shù)(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()方法是一個(gè)靜態(tài)方法,因此可以使用類名進(jìn)行訪問,如果嘗試使用類對(duì)象訪問該方法,那么也不會(huì)收到錯(cuò)誤。

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

    frequency()方法在返回頻率時(shí)可能會(huì)引發(fā)異常。

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

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

Syntax:

句法:

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

Parameter(s):

參數(shù):

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

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

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

    對(duì)象obj –表示要計(jì)算其頻率的對(duì)象。

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 ,它返回給定對(duì)象相對(duì)于給定集合的頻率。

Example:

例:

// Java program is to demonstrate the example // of int frequency() of Collectionsimport 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 listlink_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 LinkedListSystem.out.println("link_l: " + link_l);System.out.println();// By using frequency() method is to// return the object frequency of the// given collection linked istint f1 = Collections.frequency(link_l, 40);int f2 = Collections.frequency(link_l, 30);// Display frequencySystem.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 方法 示例

總結(jié)

以上是生活随笔為你收集整理的java 方法 示例_Java Collectionsfrequency()方法与示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。