Hi, I was wondering how I could search an ArrayList of Strings to find the most commonly occurring 'destination' in an 'Itinerary' object I've created (which contains a list of different destinations.)
So far I have:
public static String commonName(ArrayList<Itinerary> itinerary){
int count = 0;
int total = 0;
ArrayList<String> names = new ArrayList<String>();
Iterator<String>itr2 = 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
}
I'm having problems making an algorithm to search the array for the most commonly occurring string, or strings if there is a tie; and then displaying the number of the 'Itinerary object' (the parameter value) the string is found in. Any help would be great, thank you!!