[Java] startsWith()、endsWith()

startsWith( )
Code:
public static void main(String[] args)
{
String s1 = "Hello World";

if(s1.startsWith("Hello"))
  System.out.println("s1 starts with Hello");

if(s1.startsWith("W",6))
  System.out.println("s1 starts with W at position 6");
}


輸出:
s1 starts with Hello

endsWith( ) 
Code:
public static void main(String[] args)
{
String s1 = "Hello World";

if(s1.endsWith("World"))
  System.out.println("s1 ends with World");
}

輸出:
s1 ends with World
By Hao★

留言

熱門文章

[VB.Net] 匯出 DataGridView 資料到 Excel

[VB.Net] 使用ClosedXML匯出資料到 Excel

[Linux] Shell Script 語法