Question: ```
ArrayList searchList = new ArrayList();
ArrayList words=(ArrayList) request.getSession().getAttribute("words");
words.add("one");
words.add("twenty one");
words.add("thirty one");
words.add("two");
words.add("twenty two");
words.add("thirty two");
words.add("three");
words.add("twenty three");
words.add("thirty three");'

```

If I have this arraylist and I want to search all the strings containing one(i.e. one,twenty one and thirty one), what logic should I use? Means how should I do that?

Answer: 
```
//iterate through words
for(String str : list){
  //check if word contains the key
  if(str.contains(key)){ 
     //add its reference to another resultant list
     result.add(str);
  }
}

```
In general, when searching an item in a `List`, the best solution is to sort your `List` first using `Collections.sort()` method. Then using the `Collections.binarySearch()` method, find your element.
In this case your elements are `String` type that are `Comparable` and can be sorted alphabetically otherwise you needed to implement `Comparable` interface for your element class type.