//String方法
public class test41 {//比较两个人的姓名是否相同public static boolean eqName(String name1,String name2){return name2.equals(name1)?true:false;}//按照给定的字符的索引返回public static char findNUM(String resouse,int index){if(index<0||index>resouse.length()){return '?';}return resouse.charAt(index);}//验证邮箱的代码是否是.com结尾public static boolean mailvalite(String mail){return mail.endsWith(".com")?true:false;}//判断是否为什么开头public static boolean startvalite(String name,String perfix){return name.startsWith(perfix)?true:false;}}
测试类
public class test42 {public static void main(String[] args){String name1="歌谣";String name2="哥哥";boolean boo=test41.eqName(name1,name2);System.out.println(boo);System.out.println(name1==new String("歌谣"));char ch=test41.findNUM("我是歌谣",3);System.out.println(ch);String mail="java.com";System.out.println(test41.mailvalite(mail));String name="geyao123";boolean bool=name.startsWith("ge");System.out.println(bool);//空格除去String str1=" 261312";System.out.println(str1.length());String str2=str1.trim();System.out.println(str2.length());}
}
运行结果