- package com.simple.test;
-
- import java.util.Date;
- import java.util.Iterator;
- import java.util.Map;
-
- import org.apache.commons.lang3.ArrayUtils;
- import org.apache.commons.lang3.ClassUtils;
- import org.apache.commons.lang3.RandomStringUtils;
- import org.apache.commons.lang3.StringEscapeUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.commons.lang3.SystemUtils;
- import org.apache.commons.lang3.math.NumberUtils;
- import org.apache.commons.lang3.time.DateFormatUtils;
- import org.apache.commons.lang3.time.DateUtils;
- import org.junit.Test;
-
- public class TestString {
-
- public static void main(String[] args) {
- String[] test = { "33", "ddffd" };
- String[] test2 = { "33", "ddffd" };
- String[] test1 = { "ddffd", "33" };
-
-
- System.out.println("判斷兩個數組是否相同: " + ArrayUtils.isEquals(test, test2));
- System.out.println("判斷數組中是否包含一個對象: " + ArrayUtils.contains(test, "33"));
-
-
- System.out.println("輸出數組中的數據: "+ArrayUtils.toString(test));
-
- System.out.println("講一個二維數組轉換成MAP....");
- Map map = ArrayUtils.toMap(new String[][] { { "RED", "#FF0000" }, { "GREEN", "#00FF00" }, { "BLUE", "#0000FF" } });
-
-
-
- Iterator it = map.keySet().iterator();
- while (it.hasNext()) {
- String key = (String) it.next();
-
- System.out.println("key:" + key + "value:" + map.get(key));
- }
- System.out.println("講一個二維數組轉換成MAP 打印結束....");
-
- Iterator it1 = map.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry entry = (Map.Entry) it1.next();
-
- System.out.println("key :" + entry.getKey() + "value :" + entry.getValue());
- }
-
-
- System.out.println("取得一個類的名稱: "+ ClassUtils.getShortClassName(Test.class));
-
- System.out.println("取得一個類的包名: "+ ClassUtils.getPackageName(Test.class));
-
- System.out.println("將一個字符串轉換成數字: "+ NumberUtils.toInt("6"));
- System.out.println("將一個字符串轉換成數字, 輸入一個默認參數: "+ NumberUtils.toInt("7", 10));
-
-
- System.out.println("取得隨機字母和數字: "+RandomStringUtils.randomAlphanumeric(15));
-
- System.out.println(StringEscapeUtils.unescapeHtml3("</html>"));
-
- System.out.println(StringEscapeUtils.escapeJava("String"));
-
- System.out.println("判斷一個字符串是不是 空格: "+StringUtils.isBlank(" "));
-
- System.out.println("將數組中的內容以,分隔: "+ StringUtils.join(test, ","));
-
- System.out.println("在右邊加下字符,使之總長度爲6: "+ StringUtils.rightPad("abc", 6, 'T'));
-
- System.out.println("首字母大寫: "+ StringUtils.capitalize("abc"));
-
- System.out.println("刪除全部空格 : "+ StringUtils.deleteWhitespace(" ab c "));
-
- System.out.println("判斷是否包含這個字符 : "+ StringUtils.contains("abc", "ab"));
-
- System.out.println("取得一個字符串左邊的兩個字符: "+ StringUtils.left("abc", 2));
- System.out.println("取得一個字符串右邊的三個字符 : "+ StringUtils.right("abcd", 3));
-
-
- System.out.println("把一個字符串轉換爲BigDecimal對象: " + NumberUtils.createBigDecimal("0.25"));
- System.out.println("找出最大值: " + NumberUtils.max(new int[]{1,2,3}));
- System.out.println("JavaHome: " + SystemUtils.getJavaHome());
- System.out.println("臨時目錄位置: " + SystemUtils.getJavaIoTmpDir());
-
-
- System.out.println("日期格式處理: " + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
- System.out.println("日期加 7天: " + DateFormatUtils.format(DateUtils.addDays(new Date(), 7), "yyyy-MM-dd HH:mm:ss"));
-
- }
- }