[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★

留言

熱門文章

[C#] 將DataTable轉換成Html格式表格

[MS SQL] 查詢所有Procedure