黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

Guava教程

Guava Multiset接口

Multiset接口擴展設(shè)置有重復(fù)的元素,并提供了各種實用的方法來處理這樣的元素在集合中出現(xiàn)。

接口聲明

以下是com.google.common.collect.Multiset<E>接口的聲明:

@GwtCompatible
public interface Multiset<E>
? ?extends Collection<E>

接口方法

方法繼承

此接口繼承從以下接口方法: java.util.Collection

Multiset 示例

使用所選擇的編輯器創(chuàng)建下面的java程序,比如說 C:/> Guava
GuavaTester.java

import java.util.Iterator;
import java.util.Set;

import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;

public class GuavaTester {

   public static void main(String args[]){
      //create a multiset collection
      Multiset<String> multiset = HashMultiset.create();
      multiset.add("a");
      multiset.add("b");
      multiset.add("c");
      multiset.add("d");
      multiset.add("a");
      multiset.add("b");
      multiset.add("c");
      multiset.add("b");
      multiset.add("b");
      multiset.add("b");
      //print the occurrence of an element
      System.out.println("Occurrence of 'b' : "+multiset.count("b"));
      //print the total size of the multiset
      System.out.println("Total Size : "+multiset.size());
      //get the distinct elements of the multiset as set
      Set<String> set = multiset.elementSet();
      //display the elements of the set
      System.out.println("Set [");
      for (String s : set) {			
         System.out.println(s);		    
      }
      System.out.println("]");
      //display all the elements of the multiset using iterator
      Iterator<String> iterator  = multiset.iterator();
      System.out.println("MultiSet [");
      while(iterator.hasNext()){
         System.out.println(iterator.next());
      }
      System.out.println("]");		
      //display the distinct elements of the multiset with their occurrence count
      System.out.println("MultiSet [");
      for (Multiset.Entry<String> entry : multiset.entrySet())
      {
         System.out.println("Element: "+entry.getElement() +", Occurrence(s): " + entry.getCount());		    
      }
      System.out.println("]");		

      //remove extra occurrences 
      multiset.remove("b",2);
      //print the occurrence of an element
      System.out.println("Occurence of 'b' : "+multiset.count("b"));
   }	
}

驗證結(jié)果

使用javac編譯器編譯如下類

C:\Guava>javac GuavaTester.java

現(xiàn)在運行GuavaTester看到的結(jié)果

C:\Guava>java GuavaTester

看到結(jié)果 

Occurence of 'b' : 5
Total Size : 10
Set [
d
b
c
a
]
MultiSet [
d
b
b
b
b
b
c
c
a
a
]
MultiSet [
Element: d, Occurence(s): 1
Element: b, Occurence(s): 5
Element: c, Occurence(s): 2
Element: a, Occurence(s): 2
]
Occurence of 'b' : 3

 

 

 

 

轉(zhuǎn)載自并發(fā)編程網(wǎng)-ifeve.com

全部教程
主站蜘蛛池模板: 怡红院成人g影院 | 成人1000部免费观看视频 | 一个人看的www的视频免费 | freefr性欧美69hd | 久久人人爱 | 一本大道香蕉高清视频在线 | 久久网免费视频 | 一级片免费在线观看 | 最近资源中文字幕4 | 白丝丝袜高跟国产在线视频 | 天天射天天操天天干 | 日本a级片在线观看 | 日韩精品国产自在欧美 | 在线丝袜视频 | 在线观看亚洲天堂 | 女女色综合影院 | 日本欧美国产精品 | 免费性爱视频 | 国产在线高清不卡免费播放 | 久久国产精品久久 | 一级毛片aaaaaa视频免费看 | 国产日韩欧美在线播放 | 香蕉视频久久久 | 欧美中文字幕 | 一级毛片aaa | 欧美一级高清视频在线播放 | 国产在线高清不卡免费播放 | 有人有片的观看免费视频 | 天堂中文www在线 | 天天爽天天| 国产精品亚洲片在线观看麻豆 | 日日摸夜夜添免费毛片小说 | 国产精品久久久久久网站 | 欧美最新的精品videoss | 成人福利网 | 天天操夜夜操视频 | 亚洲手机看片 | 91精品国产品国语在线不卡 | 日韩精品一区在线观看 | 精品国产欧美 | 操美女在线观看 |