java去掉字符串前面的0:
String str = "000000001234034120"; String newStr = str.replaceAll("^(0+)", ""); System.out.println(newStr);
java截取字符串
subString(a);
subString(a,b);
一个参数的意思是,从当前的位置,截取到末尾
两个参数的意思是,从a的位置,截到b的位置的,这一串
java给定字符串,生成指定长度的字符串的工具类:
/** * 给定字符串,生成指定长度的字符串 * @param str * @param strLength * @return */ public static String addStrLength(String str,Integer strLength){ Integer nowLength = str.length(); Integer total; StringBuilder strBuilder = new StringBuilder(str); for(int i = 0; i<strLength; i++){ strBuilder.insert(0, " "); total = strBuilder.length(); if (total.equals(strLength)){ break; } } str = strBuilder.toString(); return str; } public static void main(String[] args) { String str = addStrLength("xiaoganggang",20); System.out.println(str); System.out.println(str.length()); }
遍历对象的属性:
public static void reflect(User e) throws Exception{ Class cls = e.getClass(); Field[] fields = cls.getDeclaredFields(); for(int i=0; i<fields.length; i++){ Field f = fields[i]; f.setAccessible(true); System.out.println("属性名:" + f.getName() + " 属性值:" + f.get(e)); } }
去掉字符里面的空格:
String.trim()
去掉字符里面的点号:
str.replace(".","");