Okay so I have a LinkedList, and I have a String. I want to check if the String is contained within any of the LinkedList elements. For example:
String a = "apple";
String listelement = "a bunch of apples";
LinkedList list = new LinkedList();
list.add(listelement);
if(list.containsany(a){
System.out.println("Hooray!");
}
Would result in printing "Hooray!"
Obviously list.containsany isn't a real LinkedList method, I'm just using it for this purpose.
So how can I simulate my example?
Thanks
This should do it, in order to find a node contains a particular string, you need to iterate through all the nodes. You can break the loop, if you want only 1 instance.
Also you want to use Generics. Look at the code. otherwise you will have to cast the node to a String.