Encapsulación personalizada de clases de herramientas comunes para su referencia, el contenido específico es el siguiente
paquete com.demo.utils; import java.util.arrayList; import java.util.list; import java.util.map;/** * clase de herramienta de operación de cadena clase * @author dongyangyang * @date 2016/12/28 23:12 * @version 1.0 * */clase pública public stringutils {/** * la letra inicial es la carta inicial * public static String FirstChartolowerCase (String Str) {char FirstChar = str.charat (0); if (firstchar> = 'a' && firstchar <= 'z') {char [] arr = str.toCarArray (); arr [0] += ('a' - 'a'); devolver nueva cadena (arr); } return str; } / ** * La letra inicial se capitaliza * @param str * @return * / public static string FirstCharToUpperCase (String Str) {char FirstChar = Str.Charat (0); if (firstchar> = 'a' && firstchar <= 'z') {char [] arr = str.toCarArray (); arr [0] - = ('a' - 'a'); devolver nueva cadena (arr); } return str; } / ** * Determine si está vacío * @param str * @return * / public static boolean isEtimty (String final str) {return (str == null) || (str.length () == 0); } / ** * Determine si no está vacío * @param str * @return * / public static boolean isnotempty (string final str) {return! IsEmpty (str); } / ** * 1. Determine si está en blanco * @param str * @return * / public static boolean isblank (String final str) {int strlen; if ((str == null) || ((strlen = str.length ()) == 0)) return true; for (int i = 0; i <strlen; i ++) {if (! caracteres.iswhiteSpace (str.charat (i))) {return false; }} return verdadero; } / ** * Determine si no está en blanco * @param str * @return * / public static boolean isnotblank (string final str) {return! Isblank (str); } / ** * Determine si todas las cadenas múltiples están vacías * @param cadenas * @return * / public static boolean isAllEmpty (string ... strings) {if (strings == null) {return true; } for (string str: strings) {if (isnotempty (str)) {return false; }} return verdadero; } / ** * Determine si alguna de múltiples cadenas está vacía * @param cadenas * @return * / public static boolean ishasempty (string ... strings) {if (strings == null) {return true; } for (string str: strings) {if (isEmpty (str)) {return true; }} return false; } / ** * DefaultValue es nulo o "" * @param checkValue * @param defaultValue * @return * / public static string isEtimty (string checkValue, string defaultValue) {return isEtimty (checkValue)? DefaultValue: CheckValue; } / ** * La cadena no es nula y no "" y es igual a otros * @param str * @param otros * @return * / public static boolean isnotemptyequelsother (string str, string othing) {if (isEmpty (str)) {return false; } return str.equals (otros); } / ** * La cadena no es nula y no "" y no es igual a otros * @param str * @param otro * @return * / public static boolean isnotemptyandnotequelsother (string str, string ... other) {if (isEmpty (str)) {return false; } for (int i = 0; i <other.length; i ++) {if (str.equals (otros [i])) {return false; }} return verdadero; } / ** * La cadena no es igual a otro * @param str * @param otro * @return * / public static boolean isnotequelsother (string str, string ... otros) {for (int i = 0; i <other.length; i ++) {if (otros [i] .equals (str)) {return false; }} return verdadero; } / ** * juzga la cadena no vacía * @param cadenas * @return * / public static boolean isnotempty (string ... strings) {if (strings == null) {return false; } for (string str: strings) {if (str == null || "" .equals (str.trim ())) {return false; }} return verdadero; } / ** * caracteres de comparación igual * @param valor * @param iguales * @return * / public static boolean iguales (valor de cadena, string igual) {if (isAllEmpty (valor, igual)) {return true; } return value.equals (es igual); } / ** * Las cadenas de comparación no son iguales * @param valor * @param iguales * @return * / public static boolean isnotequals (valor de cadena, string iguales) {return! Equals (valor, igual); } public static string [] Split (String Content, String SeparatorChars) {return SplitWorker (content, separatorChars, -1, falso); } public static string [] Split (String Str, String SeparatorChars, int max) {return SplitWorker (Str, separatorChars, max, falso); } cadena final estática pública [] vacía_string_array = nueva cadena [0]; cadena estática privada [] splitworker (string str, string separatorChars, int max, boolean preserveLlTokens) {if (str == null) {return null; } int len = str.length (); if (len == 0) {return vacía_string_array; } List <String> list = new ArrayList <String> (); int SizePlus1 = 1; int i = 0, inicio = 0; Boolean Match = false; boolean lastmatch = false; if (separatorChars == null) {while (i <len) {if (caracteres.iswhiteSpace (str.charat (i))) {if (match || preserveallTokens) {lastmatch = true; if (sizePlus1 ++ == max) {i = len; LastMatch = false; } list.add (str.substring (inicio, i)); Match = false; } inicio = ++ i; continuar; } lastmatch = false; Match = True; i ++; }} else if (separatorChars.length () == 1) {char sep = separatorChars.charat (0); while (i <len) {if (str.charat (i) == sep) {if (match || preserveLlTokens) {lastmatch = true; if (sizePlus1 ++ == max) {i = len; LastMatch = false; } list.add (str.substring (inicio, i)); Match = false; } inicio = ++ i; continuar; } lastmatch = false; Match = True; i ++; }} else {while (i <len) {if (separatorChars.indexof (str.charat (i))> = 0) {if (match || preserveAllTokens) {lastmatch = true; if (sizePlus1 ++ == max) {i = len; LastMatch = false; } list.add (str.substring (inicio, i)); Match = false; } inicio = ++ i; continuar; } lastmatch = false; Match = True; i ++; }} if (match || (preserveAllTokens && lastmatch)) {list.add (str.substring (inicio, i)); } return (string []) list.toarray (vacía_string_array); } / ** * Elimine los caracteres de escape * @param str * @return * / public static string escapexml (string str) {if (str == null) return ""; StringBuilder sb = new StringBuilder (); for (int i = 0; i <str.length (); ++ i) {char c = str.charat (i); switch (c) {case '/u00ff': case '/u0024': break; case '&': sb.append ("&"); romper; case '<': sb.append ("<"); romper; case '>': sb.append (">"); romper; case '/"': sb.append (" "); break; case '/' ': sb.append (" "); break; case'/'': sb.append (" ""); break; default: if (c> = '/u0000' && c <= ''/u001f ') break; if (c> ='/ue000 '&& c <='/uf8ff ') break; '/ufff0' && c <= '/ufff') break; reemplazar (string s, map <string, object> map) {stringBuilder ret = new StringBuilder ((int) (s.length () * 1.5)); Ret.append (S.Substring (Cursor, Start)). Append (map.get (S.Substring (Start + 2, End)); objs.length == 0) return s; Ret.append (S.Substring (cursor, inicio)); debe estar marcado en un estilo como {0}. {if (params == null || params.length == 0 || source == NULL || (params [count] == null) {param = null; Endindex); (isEmty (s) || separator == null) {return s; == NULL || Str, Final String Separator) {if (isEmty (str)) {return str; String toString (byte [] bytes) {try {return new String (bytes, "utf-8"); str.getBytes ("utf-8");Lo anterior es todo el contenido de este artículo. Espero que sea útil para el aprendizaje de todos y espero que todos apoyen más a Wulin.com.