判断字符串的开头和结尾

package com.text_1;

public class lianxi1111 {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		//代码实现判断字符串的开头和结尾
		String str="jnjcubhksbwiowhfkalohafwac";
		 
		if (str.indexOf("jnj")==0)
		{
			System.out.println("jnj"+"是字符串的开头");
		}
		else
		{
			System.out.println("cuowu");
		}
	    //System.out.println(str.length());
	    
		//System.out.println(str.substring(str.length()-3));
		String str2 = "wac";
		if(str.substring(str.length()-3).equals(str2))
		{
			System.out.println("字符串的结尾是"+"wac");
		}
		else
		{
			System.out.println("cuowu");
		}

	}

}

原文地址:https://www.cnblogs.com/jakeasd/p/5491635.html