List of usage examples for java.util Arrays sort
public static void sort(Object[] a)
From source file:Main.java
public static double[] merge(double[] a, double[] b) { int N = a.length; int M = b.length; int size = M + N; for (double elementB : b) { if (Arrays.binarySearch(a, elementB) >= 0) { size--;//from w w w .j a v a 2s. c om } } double[] c = new double[size]; for (int i = 0; i < a.length; i++) { c[i] = a[i]; } for (int i = a.length, j = 0; j < b.length; j++) { if (Arrays.binarySearch(c, b[j]) < 0) { c[i] = b[j]; i++; } } Arrays.sort(c); return c; }
From source file:Main.java
private static int[] distinct(int[] iValues) { Arrays.sort(iValues); List tempList = new ArrayList(); tempList.add(new Integer(iValues[0])); for (int i = 1; i < iValues.length; i++) { if (iValues[i] != iValues[i - 1]) { tempList.add(new Integer(iValues[i])); }//from ww w . ja v a2s .c om } int[] result = new int[tempList.size()]; for (int i = 0; i < result.length; i++) { result[i] = ((Integer) tempList.get(i)).intValue(); } return result; }
From source file:Main.java
private static String[] distinct(String[] sValues) { Arrays.sort(sValues); List tempList = new ArrayList(); tempList.add(sValues[0]);//from w w w .j ava2s .c om for (int i = 1; i < sValues.length; i++) { if (!sValues[i].equals(sValues[i - 1])) { tempList.add(sValues[i]); } } String[] result = new String[tempList.size()]; for (int i = 0; i < result.length; i++) { result[i] = (String) tempList.get(i); } return result; }
From source file:Main.java
/** * Get all temp files.//from w ww. j av a2 s . c om * * @return The list of existing temp files. */ public static File[] getTempCameraFiles() { File tempDir = getTempCameraFolder(); File[] files = tempDir.listFiles(new FileFilter() { @Override public boolean accept(@NonNull final File file) { return file.isFile(); } }); if (files == null) { files = new File[0]; } Arrays.sort(files); return files; }
From source file:Main.java
public static <T> boolean containArray(T[] source, T[] target) { if (target == null || target.length == 0) return false; Arrays.sort(source); Arrays.sort(target);/*from ww w. j ava 2s .co m*/ for (T tech : target) { if (Arrays.binarySearch(source, tech) < 0) { continue; } else { return true; } } return false; }
From source file:Main.java
/** * Return a sorted array of holidays for a given year. * * @param year//from w ww . j a v a 2 s .c o m * The year to get holidays for. * @return The array of holidays, sorted by date. */ public static Date[] getHolidays(int year) { Set<Date> days = getHolidaySet(year); Date[] dates = days.toArray(new Date[days.size()]); Arrays.sort(dates); return dates; }
From source file:Main.java
public static double calculateMedian(double[] fs) { Arrays.sort(fs); return fs[fs.length / 2]; }
From source file:Main.java
public static Map<String, List<String>> createDictionary(Context context) { try {//w w w. ja va 2 s .c om AssetManager am = context.getAssets(); InputStream is = am.open(DICTIONARY_FILENAME); Scanner reader = new Scanner(is); Map<String, List<String>> map = new HashMap<String, List<String>>(); while (reader.hasNextLine()) { String word = reader.nextLine(); char[] keyArr = word.toCharArray(); Arrays.sort(keyArr); String key = String.copyValueOf(keyArr); List<String> wordList = map.get(key); if (wordList == null) { wordList = new LinkedList<String>(); } wordList.add(word); map.put(key, wordList); } reader.close(); return map; } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } return null; }
From source file:Main.java
static int[] getSwitchKeys(Map buckets) { int[] keys = new int[buckets.size()]; int index = 0; for (Iterator it = buckets.keySet().iterator(); it.hasNext();) { keys[index++] = ((Integer) it.next()).intValue(); }/* www . j av a 2 s . co m*/ Arrays.sort(keys); return keys; }
From source file:Main.java
public static String[] copySortArray(String[] values) { if (values == null) { return null; }//from w w w. ja va 2 s.c o m String[] copy = new String[values.length]; System.arraycopy(values, 0, copy, 0, values.length); Arrays.sort(copy); return copy; }