Searching and printing string results from an Arraylist. Having difficulty.
Hi, been having trouble with the last two methods of an assignment.
Basically I need to search an arraylist for a string that matches for example, 'waterford' and print to screen each of these results.
Also we need to print to screen an address, based on a name being entered.
What would be the best way to implement this, and would HashMap or HashSet be better?
We've been thinking along the lines of this
public void searchByCounty()
int index =0;
boolean found = false;
while(index < addressLine.size() && !found)
String county = nam.get(index);
found = true;
Re: Searching and printing string results from an Arraylist. Having difficulty.
If you do not need multiple entries or proper ordering, a HashSet would work. Although the Hashset is founded upon a HashMap, if you don't need key/value pairs you can easily go with HashSet. If you want to link up locations with multiple hashsets (such as key a HashMap with street -> city, and city->county, and count->country, etc...), HashMap would work well. One more note, if you place custom written objects in the Map or Set you need to override and implement the hashCode() and equals() methods.