判定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));
}
}
}
//对象
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));
}
}
}