[Java] startsWith()、endsWith()
startsWith( )
endsWith( )
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★
留言
張貼留言
歡迎留言