国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Spring Utils工具類常用方法實例

瀏覽:45日期:2023-09-08 16:23:43

Spring提供的工具類,主要用于框架內部使用,這個類提供了一些簡單的方法,并且提供了易于使用的方法在分割字符串,如CSV字符串,以及集合和數組。

StringUtils提供常用的方法如下:

判斷對象對象是否為null或者空字符串

public static boolean isEmpty(@Nullable Object str) {return (str == null || ''.equals(str));}

判斷給的序列是否為空或者length為0

public static boolean hasLength(@Nullable CharSequence str) {return (str != null && str.length() > 0);}public static boolean hasLength(@Nullable String str) {return (str != null && !str.isEmpty());}

判斷字符串是否以某個字符串開頭

public static boolean startsWithIgnoreCase(@Nullable String str, @Nullable String prefix) {return (str != null && prefix != null && str.length() >= prefix.length() &&str.regionMatches(true, 0, prefix, 0, prefix.length()));}

判斷字符串是否以某個字符串結尾

public static boolean endsWithIgnoreCase(@Nullable String str, @Nullable String suffix) {return (str != null && suffix != null && str.length() >= suffix.length() &&str.regionMatches(true, str.length() - suffix.length(), suffix, 0, suffix.length()));}

用另一個字符串替換字符串中出現的所有子字符串

public static String replace(String inString, String oldPattern, @Nullable String newPattern) {if (!hasLength(inString) || !hasLength(oldPattern) || newPattern == null) {return inString;}//oldPattern字符串第一次出現的位置int index = inString.indexOf(oldPattern);if (index == -1) {// no occurrence -> can return input as-isreturn inString;}//字符串長度int capacity = inString.length();if (newPattern.length() > oldPattern.length()) {capacity += 16;}StringBuilder sb = new StringBuilder(capacity);int pos = 0; // our position in the old stringint patLen = oldPattern.length();while (index >= 0) {sb.append(inString, pos, index);sb.append(newPattern);pos = index + patLen;index = inString.indexOf(oldPattern, pos);}// append any characters to the right of a matchsb.append(inString, pos, inString.length());return sb.toString();}

根據給定的路徑規范化路徑

public static String cleanPath(String path) {if (!hasLength(path)) {return path;} //用新字符串替換舊字符串String pathToUse = replace(path, WINDOWS_FOLDER_SEPARATOR, FOLDER_SEPARATOR);// Shortcut if there is no work to doif (pathToUse.indexOf(’.’) == -1) {return pathToUse;}// Strip prefix from path to analyze, to not treat it as part of the// first path element. This is necessary to correctly parse paths like// 'file:core/../core/io/Resource.class', where the '..' should just// strip the first 'core' directory while keeping the 'file:' prefix.int prefixIndex = pathToUse.indexOf(’:’);String prefix = '';if (prefixIndex != -1) {prefix = pathToUse.substring(0, prefixIndex + 1);if (prefix.contains(FOLDER_SEPARATOR)) {prefix = '';}else {pathToUse = pathToUse.substring(prefixIndex + 1);}}if (pathToUse.startsWith(FOLDER_SEPARATOR)) {prefix = prefix + FOLDER_SEPARATOR;pathToUse = pathToUse.substring(1);}String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR);LinkedList<String> pathElements = new LinkedList<>();int tops = 0;for (int i = pathArray.length - 1; i >= 0; i--) {String element = pathArray[i];if (CURRENT_PATH.equals(element)) {// Points to current directory - drop it.}else if (TOP_PATH.equals(element)) {// Registering top path found.tops++;}else {if (tops > 0) {// Merging path element with element corresponding to top path.tops--;}else {// Normal path element found.pathElements.add(0, element);}}}// Remaining top paths need to be retained.for (int i = 0; i < tops; i++) {pathElements.add(0, TOP_PATH);}// If nothing else left, at least explicitly point to current path.if (pathElements.size() == 1 && ''.equals(pathElements.getLast()) && !prefix.endsWith(FOLDER_SEPARATOR)) {pathElements.add(0, CURRENT_PATH);}return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR);}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 香蕉视频亚洲一级 | 成年人在线观看视频免费 | 久草热久 | 亚洲国产精品成人综合久久久 | 日韩美女一级毛片 | 神马国产| 国产午夜精品不卡视频 | 免费在线精品视频 | 日本在线观看免费视频网址 | 欧美成人免费观看久久 | 欧美亚洲黄色 | 一级做a级爰片性色毛片视频 | 精品一区二区久久 | 欧洲美女与男人做爰 | 国产精品成人观看视频网站 | 亚欧色视频在线观看免费 | 日本免费人成黄页在线观看视频 | 黄色欧美视频 | 日本在线不卡免 | 日韩在线专区 | 久久国产成人精品国产成人亚洲 | 亚洲一区二区三区四区在线观看 | 中文偷拍视频在线观看 | 久久久国产免费影院 | 午夜精品视频在线观看美女 | 一级爱做片免费观看久久 | 亚洲精品欧洲久久婷婷99 | 欧美一级成人免费大片 | 欧美一级毛片在线一看 | 久久99精品久久久久久青青91 | 国产成人在线免费视频 | 欧美特欧美特级一片 | 国产精品三级在线播放 | 91热久久免费频精品动漫99 | 欧美大尺码毛片 | 亚洲精品中文字幕一区 | 欧美最大成人毛片视频网站 | 九九国产在线观看 | 欧美男人操女人 | 日本一级毛片在线看 | 国产精品久久久久久久久99热 |