第一种是加号;
第二种是StringBuffer或者StringBuilder的append
第三种是concat()
判断中文字符串长度的方法:
/** * 判断汉字的长度 * @param str * @return */ public static int stringLength(String str) { int stringLength = 0; try { if (str != null && !str.equals("")) { stringLength = str.getBytes("GB18030").length; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return stringLength; }
指定长度生成字符串,多的补空格:
public static String addStrLength(String str,Integer strLength){ if(str != null){ Integer nowLength = str.length(); Integer total; for(int i = 0; i<strLength; i++){ str = str + " "; total = stringLength(str); if(total.equals(strLength)){ break; } } return str; }else { str = ""; for (int i=0;i<strLength;i++){ str = str+" "; } return str; } }