JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

How to find a string ends with another string value in java?


Description:

Below example shows how to find whether a string value ends with another string value. By using endsWith() method, you can get whether the string ends with the given string or not. Also this method tells that the string occurence at a specific position.


Code:
package com.myjava.string;

public class MyStringEnd {

    public static void main(String a[]){
    
        String str = "This is a java string example";
        if(str.endsWith("example")){
            System.out.println("This String ends with example");
        } else {
            System.out.println("This String is not ending with example");
        }
        if(str.endsWith("java")){
            System.out.println("This String ends with java");
        } else {
            System.out.println("This String is not ending with java");
        }
    }
}

Example Output

This String ends with example
This String is not ending with java

Other String Function Examples

Knowledge Centre
What is java static import?
By using static imports, we can import the static members from a class rather than the classes from a given package. For example, Thread class has static sleep method, below example gives an idea:

import static java.lang.Thread;
public class MyStaticImportTest {
public static void main(String[] a) {
try{
sleep(100);
} catch(Exception ex){

}
}
}
Famous Quotations
Never argue with a fool, onlookers may not be able to tell the difference.
-- Mark Twain

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2022 by Nataraja Gootooru. All Rights Reserved.