|
package org.eline.core.web.support;
import java.util.Hashtable;
/** *//*******************************************************************************
*
* @author zdw
*
*/
public class ObjectFilter
{
public static void main(String[] args)
{
// String 测试
String arr[] =
{ "13111", "13112", "13111" };
ObjectFilter sf = new ObjectFilter();
Object results[] = sf.filter(arr);
System.out.println(results.length);
for (int i = 0; i < results.length; ++i)
{
System.out.println(results[i]);
}
// 整形测试
Integer arr2[] =
{ 1, 3, 5, 7, 1, 2, 4, 5 };
Object results2[] = sf.filter(arr2);
for (int i = 0; i < results2.length; ++i)
{
System.out.println(results2[i]);
}
}
/** *//***************************************************************************
* 过滤的方法
*
* @param arr
* 要过滤的数组
* @return
*/
public Object[] filter(Object arr[])
{
Hashtable<Object, Object> hashtable = new Hashtable<Object, Object>();
for (int i = 0; i < arr.length; ++i)
{
hashtable.put(arr[i], arr[i]);
}
Object results[] = null;
results = hashtable.values().toArray();
return results;
}
}
|