Java判断字符串的开头和结尾

1、判断字符串的开头:

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

输出结果:

2、判断字符的结尾

String str="abcdefabc";
int end=str.lastIndexOf("abc");
 if(end==str.length()-3)
{
	System.out.println("结尾是abc");
}
 else
{
	System.out.println("结尾不是abc");
}
原文地址:https://www.cnblogs.com/mutougezi/p/5491462.html