How to check if a String contain substring using contains() in Java

1 Answer

0 votes
package javaapplication1;

import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        try {

            String s = "java code";

            boolean b = s.contains("ja");
            System.out.println(b);
            
            b = s.contains("de");
            System.out.println(b);
 
            b = s.contains("xe");
            System.out.println(b);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
true
true
false
  
 */

 



answered Nov 21, 2016 by avibootz

Related questions

1 answer 211 views
3 answers 236 views
1 answer 172 views
1 answer 128 views
1 answer 149 views
...