My else statement is not effective but if statement is. Java : <p>I was going to let user enter 10 names and make it as array.
Then again I will let user to enter the names they want to search, then present the search result.
However, when I search something that was not in the array, the result still shows it. Is any problem in my code? Hope anyone could help, thanks.</p>

<pre><code>import java.util.Scanner;
import java.util.*;

public class Main 
{
static List&lt;String&gt; name = new ArrayList&lt;String&gt;();

public static void main (String[]args)
{   
    Scanner input=new Scanner(System.in);
    Scanner input2=new Scanner(System.in);

    int i;
    String sname;

    System.out.println("Please enter 10 student names.");
    for(i=1;i&lt;11;i++){
    name.add(input.next());
    }

    System.out.println("Namelist is " + name);
    String[] namearray = name.toArray(new String[0]);
    System.out.println("Arraylist is "+ Arrays.toString(namearray));

    System.out.println("Please enter the names that you want to search.");
    sname=input2.nextLine();

    search(namearray, sname);
}

public static void search(String[]namearray,String sname)
{
    int i;
    boolean check;

    for(i = 0; i &lt; namearray.length; i++){
          if(namearray[i].equals(sname))
             check=true;
          else
              check=false;
    }

    if(check=true){
        System.out.println("Found Result: "+sname);
    }
    else if (check=false){
        System.out.println("Not Found.");
    }
}
}
</code></pre>

<p>Thank you.</p>
