1.

Check if a string ends with a specific substring

Answer»

The endsWith() method is used to check whether a string ends with a specific string or not.

Here, we are checking whether the given string ends with the substring “one”:

PUBLIC class Example {  public STATIC VOID MAIN(String[] args) {     String s = "Mobile Phone";     if(s.endsWith("one")) {       System.out.println("Ends with the specified word!");     }     ELSE {       System.out.println("Does not end with the specified word!");        }  } }

The output:

Ends with the specified word!


Discussion

No Comment Found