java搜索string_java – 在数组列表中搜索最常见的String
我想知道如何搜索字符串的ArrayList以找到我創建的“行程”對象中最常出現的“目的地”(其中包含不同目的地的列表.)
到目前為止,我有:
public static String commonName(ArrayList itinerary){
int count = 0;
int total = 0;
ArrayList names = new ArrayList();
Iteratoritr2 = names.iterator();
while(itr.hasNext()){
Itinerary temp = itr.next();
if(temp.iterator().hasNext()){ //if its has destinations
// Destination object in itinerary object
Destination temp2 = temp.iterator().next();
String name = temp2.getDestination().toLowerCase().replace(" ", "");
if(names.contains(name)){
count = count + 1;
//do something with counting the occurence of string name here
}
我在制作一個算法來搜索數組中最常出現的字符串時遇到問題,或者如果存在平局就會出現字符串;然后顯示找到字符串的’Itinerary對象'(參數值)的編號.任何幫助都會很棒,謝謝!
總結
以上是生活随笔為你收集整理的java搜索string_java – 在数组列表中搜索最常见的String的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java属于面相_[Java教程]面相对
- 下一篇: java语言程序设计第六章答案_Java