Hello everyone, got a quick question. I have an ArrayList that I am trying to search through and print what I find. For example here is my code:
public void read(Scanner in){
while(in.hasNextLine()){
// reads in lines from the file
String l = in.nextLine();
String n = in.nextLine();
// adds items to the ArrayList
byKey.add(new DisneyItem(l,n));
}
Collections.sort(byKey);
}
byKey is my ArrayList, and it is taking in lines from a .txt file that has a location and a name, (l = location, n = name). Here is where I run into trouble, I need to run a Linear Search to search through the ArrayList by location(l), and the print the name(n). My Linear Search looks like this,
public String lookUp(String l){
for(int i = 0; i < byKey.size(); i++){
if(byKey.getKey() == l)
return byKey[i].getVale
}
}
I'm a little lost with getting my linear search set up, could anybody maybe point me in the right direction with what to do?
Thanks