1、判断字符串的开头:

        String str="abcdefabc";
if(str.indexOf("abc")==0)
{
    System.out.println("开头是abc");
}
else
{
    System.out.println("开头不是abc");
}

2、判断字符的结尾

String str="abcdefabc";
 if(str.lastIndexOf("abc")==str.length()-3)
{
    System.out.println("结尾是abc");
}
 else
{
    System.out.println("结尾不是abc");
}