IN JAVA, HOW CAN I TEST IF AN ARRAY CONTAINS A CERTAIN VALUE?

Royce Roy

Total Post:149

Points:1043
Posted by  Royce Roy
Java 
 1052  View(s)
Ratings:
Rate this:

I have a String[] with values like so:

public static final String[] VALUES = new String[] {"AB","BC","CD","AE"};

Given String s, is there a good way of testing whether VALUES contains s?

  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: In Java, how can I test if an Array contains a certain value?

    Arrays.asList(yourArray).contains(yourValue)

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!