packagecom.sicdt.library.core.utils;importjava.util.ArrayList;importjava.util.Arrays;importjava.util.Collection;importjava.util.Collections;importjava.util.List;importjava.util.Map;/***

*
类 名: 集合,数组工具

*
描 述: 描述类完成的主要功能

*
作 者: shizhenwei

*
创 建: 2017年5月15日

*
版 本: v0.0.2

*

*
历 史: (版本) 作者 时间 注释*/

public classArrayUtils {/*** 判断是否为空

*@paramcollection

*@return

*/

public static boolean isEmpty(Collection>collection){return collection == null ||collection.isEmpty();

}/*** 判断是否为空

*@parammap

*@return

*/

public static boolean isEmpty(Map, ?>map){return map == null ||map.isEmpty();

}/*** 判断是否为空

*@paramarray

*@return

*/

public static booleanisEmpty(Object[] array){return array == null || array.length == 0;

}/*** 判断是否为空

*@paramarray

*@return

*/

public static boolean isEmpty(Listarray){return array == null || array.size() == 0;

}public static booleanisArray(Object object) {if(object == null){return false;

}returnobject.getClass().isArray();

}public static booleanisCollection(Object object) {return object instanceofCollection;

}

@SuppressWarnings("unchecked")public static T[] objectToArray(Object obj) {if(obj == null){return (T[])new Object[0];

}if(isArray(obj)){return(T[])obj;

}else if(isCollection(obj)){return (T[]) ((Collection)obj).toArray();

}return (T[]) newObject[]{obj};

}

@SuppressWarnings("unchecked")public static ListobjectToList(Object obj){if(obj == null){returnCollections.emptyList();

}if(isArray(obj)){returnArrays.asList((T[])obj);

}else if(isCollection(obj)){return new ArrayList((Collection)obj);

}

List list = new ArrayList();

list.add((T) obj);returnlist;

}public static intsize(Object obj){if(obj == null){return 0;

}if(isArray(obj)){return((Object[])obj).length;

}if(isCollection(obj)){return ((Collection>)obj).size();

}return -1;

}public static booleancontains(T[] array, Object obj){returnArrays.asList(array).contains(obj);

}

}

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐