Match String value for one or the other - Java Language Basics

Java examples for Language Basics:String

Description

Match String value for one or the other

Demo Code

public class Main {
  public static void main(String[] args) throws Exception {
    String str = "true";

    // This will test against both upper & lower case "T"...this will be TRUE
    boolean result = str.matches("[Tt]rue|[Ff]alse]"); 
    System.out.println(result);//w  ww.  j  av  a  2  s.com
  }
}

Result


Related Tutorials