A สตริง เป็นวัตถุที่แสดงถึงลำดับอักขระที่ไม่เปลี่ยนรูปแบบ และไม่สามารถเปลี่ยนแปลงได้เมื่อสร้างแล้ว java.lang.String สามารถใช้คลาสเพื่อสร้างวัตถุสตริงได้
เราสามารถใช้ endsWith() วิธีการของ สตริง class เพื่อตรวจสอบว่า string ลงท้ายด้วย string ที่ระบุหรือไม่ มันคืนค่าบูลีน จริง หรือ เท็จ .
ไวยากรณ์
public boolean endsWith(String prefix)
ตัวอย่าง
public class StringEndsWithSubStringTest {
public static void main(String[] args) {
String str = "WelcomeToTutorialsPoint";
if(str.endsWith("Point")) {
System.out.println("Ends with the specified word!");
} else {
System.out.println("Does not end with the specified word!");
}
}
} ผลลัพธ์
Ends with the specified word!