How to check if a string is end with a specified word in Java

2 Answers

0 votes
package javaapplication1;

public class JavaApplication1 {
    
    public static void main(String[] args) {
  
        String s = "java php c++";

        if (s.endsWith("c++")) {
            System.out.println("ends with C++");
        } else {
            System.out.println("not end with C++");
        }
    }    
}
   
/*
   
run:
   
ends with C++
   
*/

 



answered Oct 26, 2016 by avibootz
0 votes
package javaapplication1;

public class JavaApplication1 {
    
    public static void main(String[] args) {
  
        String s = "java php c++ PHP";

        if (s.endsWith("php")) {
            System.out.println("ends with php");
        } else {
            System.out.println("not end with php");
        }
    }    
}
   
/*
   
run:
   
not end with php
   
*/

 



answered Oct 26, 2016 by avibootz

Related questions

...