title: How to check whether a List<String> contains a specific string?
body: <p>Here's what I'm trying to do:
  I have some <code>List&lt;String&gt;</code>, I want to print a statement if the List contains a particular string, else throw an Exception but when I try the following code</p>
  
  <pre class="lang-java prettyprint-override"><code>List&lt;String&gt; fruit = new ArrayList&lt;&gt;();
  fruit.add("apple");
  fruit.add("orange");
  fruit.add("banana");
  
  for(int i = 0; i &lt; fruit.size(); i++){
     if(fruit.get(i).contains("banana"){
       System.out.println("Found");
     } else {
       throw new SkipException("could not be found");
     }
  }
  </code></pre>
  
  <p>it iterates through the List and at <code>i = 0</code> it obviously finds "apple" and immediately goes to the <code>else</code> block and throws exception. I also tried the following, but this didn't work either. </p>
  
  <pre class="lang-java prettyprint-override"><code>for(int i = 0; i &lt; fruit.size(); i++){
     if(Arrays.asList(fruit).contains("banana"){
        System.out.println("found");
     }else{
        throw new SkipException("not found");
     }
  }
  </code></pre>
  
  <p>Is there an easy way to do what I'm trying to do here?</p>