Encapsulation personnalisée des classes d'outils courantes pour votre référence, le contenu spécifique est le suivant
Package com.demo.utils; import java.util.arraylist; import java.util.list; import java.util.map; / ** * String Operation Tool Class * @author dongyangyang * @date 2016/12/28 23:12 * @version 1.0 * * / public class stringUtils * / ** * * La lettre initiale est intime * @Param Str * @rertils {/ ** * Static String FirstChartolowerCase (String Str) {char FirstChar = Str.Charat (0); if (firstchar> = 'a' && première <= 'z') {char [] arr = str.tocharArray (); arr [0] + = ('a' - 'a'); return new String (arr); } return str; } / ** * La lettre initiale devient capitalisée * @param str * @return * / public static String FirstChartoupperCase (String str) {char firstchar = str.charat (0); if (firstchar> = 'a' && première <= 'z') {char [] arr = str.tocharArray (); arr [0] - = ('a' - 'a'); return new String (arr); } return str; } / ** * Déterminez s'il est vide * @param str * @return * / public static boolean isEmpty (final String str) {return (str == null) || (str.length () == 0); } / ** * Déterminez s'il n'est pas vide * @param str * @return * / public static boolean isNotempty (final String str) {return! Isempty (str); } / ** * 1. Déterminez s'il est vide * @param str * @return * / public static boolean isblank (final String str) {int strlen; if ((str == null) || ((strlen = str.length ()) == 0)) return true; for (int i = 0; i <strlen; i ++) {if (! worist.iswhitespace (str.charat (i))) {return false; }} return true; } / ** * Déterminez s'il n'est pas vide * @param str * @return * / public static boolean isNotblank (final String str) {return! Isblank (str); } / ** * Déterminez si toutes les chaînes multiples sont vides * @param chaînes * @return * / public static boolean isallempty (String ... Strings) {if (Strings == null) {return true; } pour (String str: Strings) {if (isNotempty (str)) {return false; }} return true; } / ** * Déterminez si l'une des chaînes multiples est vide * @param chaînes * @return * / public static boolean ishasempty (String ... Strings) {if (Strings == null) {return true; } pour (String str: Strings) {if (isEmpty (str)) {return true; }} return false; } / ** * DefaultValue est null ou "" * @param checkValue * @param defaultValue * @return * / public static String isEmpty (String CheckValue, String defaultValue) {return isEmpty (CheckValue)? DefaultValue: CheckValue; } / ** * La chaîne n'est pas nul et non "" et est égale à d'autres * @param str * @param autre * @return * / public static boolean isNotempTyAndEarelsother (String str, string autre) {if (isEmpty (str)) {return false; } return str.equals (autre); } / ** * La chaîne n'est pas nul et non "" et n'est pas égale à d'autres * @param str * @param autre * @return * / public static booléen isNotempTyAndNoteQuelsother (String str, string ... other) {if (isEmpty (str)) {return false; } pour (int i = 0; i <autres.length; i ++) {if (str.equals (autre [i])) {return false; }} return true; } / ** * La chaîne n'est pas égale aux autres * @param str * @param autre * @return * / public static boolean isNotequelSother (String str, string ... other) {for (int i = 0; i <autre.length; i ++) {if (autre [i] .equals (str)) {return false; }} return true; } / ** * juge la chaîne non vide * @param cordes * @return * / public static boolean isNotempty (String ... Strings) {if (Strings == null) {return false; } pour (String str: Strings) {if (str == null || "" .equals (str.trim ())) {return false; }} return true; } / ** * Caractères de comparaison Equal * @param Valeur * @param est égal * @return * / public static boolean equals (String value, String equals) {if (isallempty (value, equals)) {return true; } return value.equals (égaux); } / ** * Les chaînes de comparaison ne sont pas égales * @param valeur * @param est égal * @return * / public static boolean isNotequals (la valeur de chaîne, la chaîne équivaut) {return! Equals (valeur, égal); } public static String [] Split (String Content, String séparatorChars) {return SplitWorker (contenu, séparatorchars, -1, false); } public static String [] Split (String Str, String séparatorChars, int max) {return SplitWorker (Str, SepreatorChars, Max, False); } public static final String [] vide_string_array = new String [0]; String statique privé [] SplitWorker (String Str, String séparatorchars, int max, boolean conservatalltokens) {if (str == null) {return null; } int len = str.length (); if (len == 0) {return vide_string_array; } List <string> list = new ArrayList <string> (); int sizeplus1 = 1; int i = 0, start = 0; booléen match = false; booléen lastmatch = false; if (séparatorChars == null) {while (i <len) {if (caractères.iswhitespace (str.charat (i))) {if (match || PreserveallTokens) {lastmatch = true; if (sizeplus1 ++ == max) {i = len; lastmatch = false; } list.add (str.substring (start, i)); matches = false; } start = ++ i; continuer; } lastmatch = false; match = true; i ++; }} else if (séparatorChars.length () == 1) {char sep = séparatorchar.Charat (0); while (i <len) {if (str.charat (i) == sep) {if (match || PreserveallTokens) {lastmatch = true; if (sizeplus1 ++ == max) {i = len; lastmatch = false; } list.add (str.substring (start, i)); matches = false; } start = ++ i; continuer; } lastmatch = false; match = true; i ++; }} else {while (i <len) {if (séparatorCharS.Indexof (str.charat (i))> = 0) {if (match || PreserveallTokens) {lastmatch = true; if (sizeplus1 ++ == max) {i = len; lastmatch = false; } list.add (str.substring (start, i)); matches = false; } start = ++ i; continuer; } lastmatch = false; match = true; i ++; }} if (match || (PreserveallTokens && lastmatch)) {list.add (str.substring (start, i)); } return (String []) list.toArray (vide_string_array); } / ** * Éliminer les caractères d'échappement * @param str * @return * / public static String EscapExml (String str) {if (str == null) return ""; StringBuilder sb = new StringBuilder (); pour (int i = 0; i <str.length (); ++ i) {char c = str.charat (i); commutateur (c) {case '/ u00ff': case '/ u0024': break; Case '&': SB.APPEND ("&"); casser; cas '<': sb.append ("<"); casser; case '>': sb.append (">"); casser; Cas '/ "': sb.append (" "); break; case '/' ': sb.append (" "); break; case' / '': sb.append (" '"); break; par défaut: if (c> =' / u0000 '&& c <=' / u001f ') Break; if (c> =' / ue000 '&& c <=' / uf8ff ') Break; '/ ufff0' && c <= '/ ufff') Break; remplacer (String s, map <string, objet> map) {stringBuilder ret = new StringBuilder ((int) (s.Length () * 1.5)); Ret.Apped (S.SubString (curseur, démarrage). OBJS.Length == 0) Ret.Apped (S.SubString (curseur, démarrage); Doit être marqué dans un style comme {0}. {if (params == null || Params. (paramètres] == null) {param = null;} else {params [count (startIndex == -1) {Break;} endIndex = startIndex + temp.length (); == null) {return s;} if (séparateur.isempty ()) {return ";} int POS = S.Indexof (séparateur); Null) {return null;} final int start = str.indexof (open); (ISEMPTY (STR)) {return Str;} if (séparateur == null) {return "";} int POS = Str.Indexof (séparateur); toString (byte [] octets) {try {return new String (bytes, "utf-8");} catch (unpportedEncodingException e) {return null;}} / ** * Converti Str.getbytes (UTF-8 ");} Catch (UnsupportEdEncodingException e) {return Null;Ce qui précède est tout le contenu de cet article. J'espère que cela sera utile à l'apprentissage de tous et j'espère que tout le monde soutiendra davantage Wulin.com.