public static String[] mergeStringArrays(String array1[], String array2[]) { if (array1 == null || array1.length == 0) return array2; if (array2 == null || array2.length == 0) return array1; List array1List = Arrays.asList(array1); List array2List = Arrays.asList(array2); List result = new ArrayList(array1List); List tmp = new ArrayList(array1List); tmp.retainAll(array2List); result.removeAll(tmp); result.addAll(array2List); return ((String[]) result.toArray(new String[result.size()])); }
A java blog with a collection of examples and tutorials on Java and related technologies. (Under maintenance with continuous updates) Be in touch with java jazzle or k2java.blogspot.com.
Wednesday, June 22, 2011
String utility : Merging 2 string arrays
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment