日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

FormatUtil

發布時間:2024/9/27 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 FormatUtil 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

package com.css.common.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
?* 用于操作字符串的工具類
?*
?* @version 1.0
?*
?*/
public class FormatUtil {
?
?/**
? * 過濾空格
? * @param str
? * @return
? */
?public static String trim(String str) {
??String temp = "";
??if(str==null){
???return temp;
??}
??for (int i = 0; i < str.length(); i++) {
???temp = (new StringBuilder()).append(temp).append(str.substring(i, i + 1).trim()).toString();
??}
??return temp;
?}

?/**
? * 判斷對象是否為空
? * @param str
? * @return
? */
?public static boolean isNotNull(Object str) {
??boolean b = false;
??if (str == null) {
???return b;
??}
??if (str instanceof String) {
???String value = str.toString();
???if (value != null && trim(value).length() > 0) {
????b = true;
???}
??} else if (str instanceof Double) {
???Double value = (Double) str;
???if (value != null && value.doubleValue() > 0) {
????b = true;
???}
??} else if (str instanceof Integer) {
???Integer value = (Integer) str;
???if (value != null && value.intValue() > 0) {
????b = true;
???}
??} else if (str instanceof Long) {
???Long value = (Long) str;
???if (value != null && value.longValue() > 0) {
????b = true;
???}
??} else if (str instanceof String[]) {
???String value[] = (String[]) str;
???if (value != null && value.length > 0) {
????b = true;
???}
??} else if (str instanceof Long[]) {
???Long value[] = (Long[]) str;
???if (value != null && value.length > 0) {
????b = true;
???}
??} else if (str instanceof Byte) {
???Byte value = (Byte) str;
???if (value != null && value.byteValue() > 0) {
????b = true;
???}
??} else if (str instanceof Map) {
???Map value = (Map) str;
???if (str != null && value.size() > 0) {
????b = true;
???}
??} else if (str instanceof List) {
???List value = (List) str;
???if (str != null && value.size() > 0) {
????b = true;
???}
??} else if (str != null) {
???b = true;
??}
??return b;
?}
?
?/**
???? * Splits a string into substrings based on the supplied delimiter
???? * character. Each extracted substring will be trimmed of leading
???? * and trailing whitespace.
???? *
???? * @param str The string to split
???? * @param delimiter The character that delimits the string
???? * @return A string array containing the resultant substrings
???? */
??? public static final List split(String str, char delimiter) {
??????? // return no groups if we have an empty string
??????? if ((str == null) || "".equals(str)) {
??????????? return new ArrayList();
??????? }

??????? ArrayList parts = new ArrayList();
??????? int currentIndex;
??????? int previousIndex = 0;

??????? while ((currentIndex = str.indexOf(delimiter, previousIndex)) > 0) {
??????????? String part = str.substring(previousIndex, currentIndex).trim();
??????????? parts.add(part);
??????????? previousIndex = currentIndex + 1;
??????? }

??????? parts.add(str.substring(previousIndex, str.length()).trim());

??????? return parts;
??? }

}

總結

以上是生活随笔為你收集整理的FormatUtil的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。