Here you can find the source of getUniqueIDsArray(int[] idArray, String ids, String seperator)
public static int[] getUniqueIDsArray(int[] idArray, String ids, String seperator)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static int[] getUniqueIDsArray(int[] idArray, String ids, String seperator) { Set<Integer> idSet = new HashSet<Integer>(); if (idArray != null) { for (int id : idArray) { idSet.add(id);// www . j a v a 2 s . c o m } } int[] tmpIdArray = transIDsToArray(ids, seperator); if (tmpIdArray != null) { for (int id : tmpIdArray) { idSet.add(id); } } int[] targetArray = new int[idSet.size()]; int idx = 0; Iterator<Integer> iterator = idSet.iterator(); while (iterator.hasNext()) { targetArray[idx] = iterator.next(); idx++; } return targetArray; } public static int[] transIDsToArray(String ids, String seprator) { if (ids == null || seprator == null) { return null; } String[] tmpArray = ids.split(seprator); List<String> validList = new ArrayList<String>(); for (int i = 0; i < tmpArray.length; i++) { if (tmpArray[i].matches("^\\d+$")) { validList.add(tmpArray[i]); } } int[] targetArray = new int[validList.size()]; for (int i = 0; i < validList.size(); i++) { targetArray[i] = Integer.valueOf(validList.get(i)); } return targetArray; } }