一串数字,112334567=》 123456
import java.awt.List;
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
int[] Nums = {1,2,3,4 };
Integer [] aa = getDistinct2(Nums);
for(int i : aa){
System.out.print(i);
}
}
/*
static Integer[] getDistinct(int num[]) {
ArrayList<Integer> list = new java.util.ArrayList<Integer>();
for (int i = 0; i < num.length; i++) {
if (!list.contains(num[i])) {//如果list数组不包括num[i]中的值的话,就返回true。
list.add(num[i]); //在list数组中加入num[i]的值。已经过滤过。
}
}
return list.toArray(new Integer[0]); //toArray(数组)方法返回数组。并要指定Integer类型。new integer[o]的空间大小不用考虑。因为如果list中的长度大于0(你integer的长度),toArray方法会分配一个具有指定数组的运行时类型和此列表大小的新数组。
}*/
static Integer[] getDistinct2 (int number[]){
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i =0;i<number.length;i++)
{
if(!list.contains(number[i])){
list.add(number[i]);
}
}
return list.toArray(new Integer[0]);
}
}
public static bool doesTargetExistsInList(int Target, int[] inputArray)
{
if (inputArray != null && inputArray.Length > 0 )
{
Hashtable inputHashTable = new Hashtable();
// This hash table will have all the items in the input array and how many times they appeard
Hashtable duplicateItems = new Hashtable();
foreach (int i in inputArray)
{
if (!inputHashTable.ContainsKey(i))
{
inputHashTable.Add(i, Target - i);
duplicateItems.Add(i, 1);
}
else
{
duplicateItems[i] = (int)duplicateItems[i] + 1;
}
}
foreach (DictionaryEntry de in inputHashTable)
{
if ((int)de.Key == (int)de.Value)
{
if ((int)duplicateItems[de.Key] > 1)
return true;
}
else if (inputHashTable.ContainsKey(de.Value))
{
return true;
}
} } return false;}