System.out.println("what is your name? ");
			
String name = kb.nextLine();
			
for(int i = 0; i < member2.size(); i++){
				
  if(member2.get(i).equals(name)){
					
     System.out.println(name + " is a member. ");
			
     break;			
}
				
else{
					
  System.out.println(name +" is not a member. ");
					
  break;
				
}

i did a system.out.println on the member2 arraylist (String arraylist) and it prints out the correct stuff. when comparing whether or not name is equal to an item in the arraylist, it always give me the else statement even if the name is in the list.

for example, member2 contains:
"john"
"william"
"xxxxx"

and then i would type in "john", and it gives me "john is not a member."

It looks to me like your if statement is executed every time you compare, that way if the first string in the ArrayList is not the one you entered it returns ___ is not a member. Try using an intermediate variable like this:

boolean found = false;
for(String s : member2)
    if(s.equals(name))
        found = true;
        
if(found)
    System.out.println(name + " is a member. ");
else
  System.out.println(name +" is not a member. ");

thanks! it works!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.