Chatbox

Các bạn vui lòng dùng từ ngữ lịch sự và có văn hóa,sử dụng Tiếng Việt có dấu chuẩn. Chúc các bạn vui vẻ!
09/10/2021 17:10 # 1
buiducduong
Cấp độ: 22 - Kỹ năng: 1

Kinh nghiệm: 17/220 (8%)
Kĩ năng: 0/10 (0%)
Ngày gia nhập: 25/09/2020
Bài gởi: 2327
Được cảm ơn: 0
Java String endsWith() Method with Example


Java String endsWith()

The Java String endsWith() method is used to check whether the string is ending with user-specified substring or not. Based on this comparison it returns the result in boolean value true if the specific suffix is matched or it returns false if the suffix does not match.

endsWith() Method Syntax

Public endsWith(suffix)

endsWith() Function Parameters

suffix – This is a suffix.

Return Data Type of endsWith() Method

  • False: Character sequence supplied in “suffix” DOES NOT matches the end sequence of the calling string
  • True: Character sequence supplied in “suffix” matches the end sequence of the calling string

Exception

None

Example of Java String endsWith() Method

public class StringEx1 {
    public static void main(String[] args) {
        String str_Sample = "Java String endsWith example";
        //Check if ends with a particular sequence
        System.out.println("EndsWith character 'e': " + str_Sample.endsWith("e"));
        System.out.println("EndsWith character 'ple': " + str_Sample.endsWith("ple"));
        System.out.println("EndsWith character 'Java': " + str_Sample.endsWith("Java"));
    }
}

Output:

EndsWith character ‘e’: true
EndsWith character ‘ple’: true
EndsWith character ‘Java’: false

The java.lang.String.endsWith() returns true if this string ends with the specified suffix.




 
Copyright© Đại học Duy Tân 2010 - 2024