欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java排序去重示例分享

 更新時(shí)間:2014年02月24日 09:11:44   作者:  
這篇文章主要介紹了java排序去重示例,對(duì)String strs = "ZZZ BBB AAA OOO ZZZ AAA ZZZ"計(jì)算出現(xiàn)個(gè)數(shù),排序去重,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

package action;
import java.util.Arrays;
import java.util.TreeSet;
public class test {
 /**
  * @param args
  */
 public static void main(String[] args) {
  String strs = "ZZZ BBB AAA OOO ZZZ AAA ZZZ BBB AAA ZZZ AAA VVV OOO CCC DDD CCC CCC KKK BBB AAA ZZZ AAA CCC KKK";
  String[] word = strs.split(" ");
  TreeSet<String> set = new TreeSet();//去重復(fù)使用TreeSet
  //排序 
  Arrays.sort(word); 
  //計(jì)算出現(xiàn)個(gè)數(shù)
  for (int i = 0; i < word.length; i++) {
   int count = 0;
   for (int j = 0; j < word.length; j++) {
    if (word[i].equals(word[j])) {
     count += 1;
    } 
   }
   set.add(word[i]+":"+count); 
  }
  //去重復(fù)
  for(String s:set){
   System.out.println(s);
  }
 }
}

相關(guān)文章

最新評(píng)論