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: 
```
for (String word : words) {
   if (word.contains("one")) {
       //we have a match
   }
}

```
You could solve this using iterators if the condition will be more complex 

```
    public interface IPredicate<T> {

        boolean check(T t);

    }

public class PredicatIterable<T> implements Iterable<T> {

        private final Iterator<T> iterator;
        private final IPredicate<T> predicate;

        public PredicatIterable(Iterable<T> iterable, IPredicate<T> predicate) {
            this.iterator = iterable.iterator();
            this.predicate = predicate;
        }

        @Override
        public Iterator<T> iterator() {
            return new Iterator<T>() {

                T current;

                @Override
                public boolean hasNext() {

                    if(iterator.hasNext()) {
                        T next = iterator.next();

                        if(predicate.check(next)) {
                            current = next;
                            return true;
                        } 
                        current = null;
                    }

                    return false;
                }

                @Override
                public T next() {
                    return current;
                }

                @Override
                public void remove() {
                    throw new RuntimeException("Invalid useage of method");
                }

            };
        }

    }

```

To validate more the single predicate you can create also method that is responsible for conuntion or alternative of two IPredicate argument.