Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking if same values

Status
Not open for further replies.

chicago1985

Technical User
Oct 11, 2007
10
US
I currently have two String objects I check to find out if they are the same value:
Code:
String str1 = "red";
String str2 = "yellow";
if (str1.equals(str2)){
      System.out.println("Equal");
}
else{
      System.out.println("Not equal");
}
Now how would I check 10 objects to find out if any of them have the same value?

Please advise.
 
another way
Code:
import java.util.Arrays;
public class ArrayTesting
{
	public static void main(String[] args)
	{
		String[] arr1 = new String[]{"one", "two", "three"};
		String[] arr2 = new String[] {"one", "two", "three"};
		if (Arrays.equals(arr1, arr2))
		{
			System.out.println("arrays are equal");
		}
		else
		{
			System.out.println("arrays are not equal");
		}
		
	}
}

Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top