java常用的语句
//判斷一個(gè)長的字符串中是否包含某一個(gè)短的字符串
if (str1.indexOf(str2) != -1) {return true;//存在
}else {return false;
} /*** 消息模板關(guān)鍵字替換* @param template 消息內(nèi)容* @param map 替換key-value* @return*/
public static String replaceTemplate(String template, Map<String, Object> map){if(!StringUtils.isBlank(template)){for (Map.Entry<String, Object> entry : map.entrySet()) {template = template.replaceAll(entry.getKey(), entry.getValue().toString());}}return template;
} /*** 生產(chǎn)的隨機(jī)串* @param num 長度* @return*/
public static String genRadomNbr(Integer num) {Random random = new Random();String result = "";for (int i = 0; i < num; i++) {result += random.nextInt(10);}return result;
} /*** 組裝返回的json數(shù)據(jù)* @param data* @param code* @param message* @return*/
public JSONObject assemblyJson(Object data, String code, String message) {JSONObject jsonObject = new JSONObject();// 創(chuàng)建對象jsonObject.put("data", data);// 數(shù)據(jù)不為空的時(shí)候設(shè)置返回?cái)?shù)據(jù)jsonObject.put("message", message);// 設(shè)置狀態(tài)數(shù)據(jù)jsonObject.put("code", code);return jsonObject;} //刪除某一字符
public static String deleteStr(String str, char delChar){String delStr = "";for (int i = 0; i < str.length(); i++) {if(str.charAt(i) != delChar){delStr += str.charAt(i);}}return delStr;
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/gjq1126-web/p/11212834.html
總結(jié)
- 上一篇: 固态硬盘用软件测试温度高,硬盘温度过高的
- 下一篇: python数据结构_大O符号_学习笔记