public class Main
{
public static void main(String[] args)
/*
n o w j a v a . c o m - 时 代 Java
*/
{
String[] strings = {"started", "starting", "ended", "ending"};
// test method startsWith
for (String string : strings)
{
if (string.startsWith("st"))
System.out.printf("\"%s\" starts with \"st\"\n", string);
}
System.out.println();
// from 时 代 J a v a - N o w J a v a . c o m
// test method startsWith starting from position 2 of string
for (String string : strings)
{
if (string.startsWith("art", 2))
System.out.printf(
"\"%s\" starts with \"art\" at position 2\n", string);
}
System.out.println();
// test method endsWith
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。