BattleMacross正确,传一个参数就可以了,不需要其他人那么繁琐了
String s = "jljfskjflsjdflksjdf";
String sub = s.subString(s.length ()- 4,s.length()); //最后四个字符
public static void main(String[] args){
String str = "happy";
String strLast;
strLast = str.substring(str.length()-4);
System.out.println(strLast);
}
输出结果为:appy
package test;
public class SplitLast4 {
/**
* @param args
* @throws UnsupportedEncodingException
*/
public static void main(String[] args){
// TODO Auto-generated method stub
String s = "ghj";
String str = new SplitLast4().splitLastFourChars(s);
System.out.println(str);
}
String splitLastFourChars(String s){
String str = "";
if(s.length()<4){
return s;
}else{
for(int i=s.length()-4;i
}
return str;
}
}
}
String s = "111sdfsdfsdfsfsaaxiahello啊";
String s1 = s.substring(s.length()-4,s.length());
System.out.println(s1);