public class stringJiequ {
public static void main(String[] args) {
// TODO Auto-generated method stub
String col="21";
String levelString = stringJiequ.level(col);
System.out.println(levelString);
char levelFirst = stringJiequ.levelFirst(col);
System.out.println(levelFirst);
}
/**
* @author: zhangxubin
* @date: 2019年10月9日 下午5:31:56
* @Description
*/
public static String level(String color){
String level;
level=color.substring(0,1);
return level;
}
public static char levelFirst(String color){
char level = color.charAt(0);
return level;
}
}
截取字符串有多种方法。这里推荐两种比较常用的。