判定List<String>中数量

判定List<String>中String数量
//对象

public class WordsCounter
{
public String text;
public int count;
public WordsCounter()
{
text="";
count=0;
}

public WordsCounter(String t,int c)
{
text=t;
count=c;
}
}

//方法
public class Test
{
List<WordsCounter> wordsCountList=new ArrayList<WordsCounter>();
List<String> wordsList=new ArrayList<String>();
//统计词汇频数
for(String word:wordsList)//循环wordsList中的看看这个分词在List中个数
{
boolean match=false;//标示是否存在
for(int i=0;i<wordsCountList.size();i++)
{
if(word.equals(wordsCountList.get(i).text))//如果存在
{
wordsCountList.get(i).count++;
match=true;//如果存在数字加1,match告知外部
break;
}
}
if(match==false)//如果没有的话,加入对象
{
wordsCountList.add(new WordsCounter(word,1));
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值