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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 炸油条油里为什么放水?
- 下一篇: LocationPathUtil