在arraylist中找到类似的字符串 [英] Find similar string in arraylist
本文介绍了在arraylist中找到类似的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您如何在arraylist中找到类似的字符串并计算重复的字符串
解决方案
一旦您定义了'相似性测试',这是一个确定if的方法传递的字符串是否相似你可以将这样的方法应用于列表中的字符串对,并在测试通过时递增计数器。
编写测试字符串相似性的方法一项微不足道的任务,很大程度上取决于(如谢尔盖所说)你的要求。
示例代码:
List< string> list = new ArrayList< string>();
list.add( aaa);
list.add( bbb);
list.add( aaa);
设置< string> unique = new HashSet< string>(list);
for ( String key:unique){
System.out.println( key + : + Collections.frequency(list,key));
}< / string>< / string>< / string>< / string>
参考:http://stackoverflow.com/questions/5211194/count-occurences-of-words-in-arraylist [ ^ ]
Hi how do I find similiar string in an arraylist and count the duplicated strings
解决方案
Once you defined a 'similitude test', that is a method establishing if the passed strings are similar or not you could apply such a method to the string pairs in your list and increment the counter whenever the test is passed.
Writing a method testing the similarity of the strings it is not a trivial task and heavily depends (as noted by Sergey) on your requirements.
sample code:
List<string> list = new ArrayList<string>(); list.add("aaa"); list.add("bbb"); list.add("aaa"); Set<string> unique = new HashSet<string>(list); for (String key : unique) { System.out.println(key + ": " + Collections.frequency(list, key)); }</string></string></string></string>
refer : http://stackoverflow.com/questions/5211194/count-occurences-of-words-in-arraylist[^]
这篇关于在arraylist中找到类似的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文