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
Can you list serialization methods?
Serialization interface does not have any methods. It is a marker interface. It just tells the JVM that your class can be serializable.
Famous Quotations
The greatest obstacle to discovery is not ignorance; it is the illusion of knowledge.
-- Daniel J. Boorstin

About Author

Most Visited Pages

Other Interesting Sites

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