[자바] org. apache. comons. lang 3 기능 예시

6207 단어
org. apache. comons. lang 3 기능 예시
 
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" }; 
 
        // 1.          ,       ,            
        System.out.println("          : " + ArrayUtils.isEquals(test, test2)); 
        System.out.println("             : " + ArrayUtils.contains(test, "33")); 
         
        // 2.{33,ddffd}       {,}    . 
        System.out.println("        : "+ArrayUtils.toString(test)); 
         
        System.out.println("          MAP...."); 
        Map map = ArrayUtils.toMap(new String[][] { { "RED", "#FF0000" }, { "GREEN", "#00FF00" }, { "BLUE", "#0000FF" } }); 
        // 3.toMap     ,      Each element of the array 
        // must be either a {@link java.util.Map.Entry} or an Array, 
        //          map   ,   keySet.iterator(); 
        Iterator it = map.keySet().iterator(); 
        while (it.hasNext()) { 
            String key = (String) it.next(); 
            // it.next()   key 
            System.out.println("key:" + key + "value:" + map.get(key)); 
        } 
        System.out.println("          MAP     ...."); 
        //    ,   entrySet()  , 
        Iterator it1 = map.entrySet().iterator(); 
        while (it.hasNext()) { 
            Map.Entry entry = (Map.Entry) it1.next(); 
            // it1.next()   key value 
            System.out.println("key :" + entry.getKey() + "value :" + entry.getValue()); 
        } 
 
        // 4.     
        System.out.println("        : "+ ClassUtils.getShortClassName(Test.class)); 
        //       
        System.out.println("        : "+ ClassUtils.getPackageName(Test.class)); 
        // 5.NumberUtils 
        System.out.println("           : "+ NumberUtils.toInt("6")); 
        System.out.println("           ,         : "+ NumberUtils.toInt("7", 10));//   7          null   10  
         
        // 6.           
        System.out.println("         : "+RandomStringUtils.randomAlphanumeric(15)); 
        // 7.StringEscapeUtils 
        System.out.println(StringEscapeUtils.unescapeHtml3("

좋은 웹페이지 즐겨찾기