Created
June 9, 2013 19:29
-
-
Save gmfc/5744844 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static int[] merge(Comparable[] arg1, Comparable[] arg2) | |
| { | |
| //convert arrays to collections (lists) | |
| Collection coll1 = Arrays.asList(arg1); | |
| Collection coll2 = Arrays.asList(arg2); | |
| //Create a SortedSet from the first collection | |
| SortedSet sorter = new TreeSet(coll1); | |
| //Add the second collection | |
| sorter.addAll(coll2); | |
| //Create an array to hold the results | |
| int[] merged = new int[sorter.size()]; | |
| Iterator itSorted = sorter.iterator(); | |
| for (int i = 0; itSorted.hasNext(); i++) { | |
| merged[i] = ((Integer)itSorted.next()).intValue(); | |
| } | |
| //return the SortedSet as an array | |
| return(merged); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment