Here you can find the source of unique(double[] in)
Parameter | Description |
---|---|
in | the input array |
public static double[] unique(double[] in)
//package com.java2s; /**/* w ww.j a va 2 s.com*/ * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ import java.util.Arrays; public class Main { /** * Same behaviour as mathlab unique. * * @param in the input array * @return a sorted array with no duplicates values */ public static double[] unique(double[] in) { Arrays.sort(in); int n = in.length; double[] temp = new double[n]; temp[0] = in[0]; int count = 1; for (int i = 1; i < n; i++) { if (Double.compare(in[i], in[i - 1]) != 0) { temp[count++] = in[i]; } } if (count == n) { return temp; } return Arrays.copyOf(temp, count); } /** * Same behaviour as mathlab unique. * * @param in the input array * @return a sorted array with no duplicates values */ public static int[] unique(int[] in) { Arrays.sort(in); int n = in.length; int[] temp = new int[n]; temp[0] = in[0]; int count = 1; for (int i = 1; i < n; i++) { if (in[i] != in[i - 1]) { temp[count++] = in[i]; } } if (count == n) { return temp; } return Arrays.copyOf(in, count); } }