Results 1 to 4 of 4
  1. #1
    tyang is offline Member
    Join Date
    Jan 2010
    Posts
    44
    Rep Power
    0

    Default find the unique values of a double array

    How can I find the unique values of a double array?
    e.g.
    double a[] = {1,10,3,3,3,1};
    How can I get {1,3,10}?

    Many thanks!

  2. #2
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Java Code:
    public class UniqueInt {
    	
    
    	
    	public static void main(String[] args) {
    		
    		int[] a = {1,10,3,3,3,1};
    		int[] temp = new int[a.length-1];
    		int[] anotherTemp;
    		
    			boolean unique = true;
    			
    			temp[0] = a[0];
    			int count = 1;
    			for (int tempInt : a) {
    				for (int tempTempInt : temp)
    					if (tempInt == tempTempInt)
    						unique = false;
    				if (unique)
    					temp[count++] = tempInt;
    				unique = true;
    			}
    			
    			anotherTemp = new int[count];
    			
    			//trim the array
    			for (int i=0; i<count; i++)
    				anotherTemp[i] = temp[i];
    
    			//print the new array
    			for (int x : anotherTemp)
    				System.out.println(x);
    
    			
    	}
    
    }
    There is probably a very simple way of doing this.
    Last edited by Lil_Aziz1; 02-08-2010 at 04:39 AM.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  3. #3
    djbeko06 is offline Member
    Join Date
    Sep 2011
    Posts
    4
    Rep Power
    0

    Default Re: find the unique values of a double array

    How can I find the number of unique Strings of a String array?
    e.g.
    double a[] = {aab,aba,aca,aab,adc,zzz,aca};
    How can I get 2?

    Many thanks!

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default Re: find the unique values of a double array

    Please don't hijack someone else's thread.

    Where is your String array?

Similar Threads

  1. Find-Guru connects Teachers and Students in a unique way
    By gonnalakshmi09 in forum Java Software
    Replies: 0
    Last Post: 09-23-2009, 02:54 PM
  2. Replies: 5
    Last Post: 07-28-2009, 11:22 PM
  3. manipulation in double dimensional array
    By akulkarni1234 in forum New To Java
    Replies: 1
    Last Post: 07-19-2009, 08:37 PM
  4. mutliplicatio of double values
    By katkamravi in forum New To Java
    Replies: 2
    Last Post: 04-13-2009, 03:28 PM
  5. Unique element in an array
    By revathi17 in forum New To Java
    Replies: 2
    Last Post: 12-31-2007, 09:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •