File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing ArrayList and double array[]

 
Gabriel White
Ranch Hand
Posts: 233
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I have some code...that doesn't work. I am trying to find the common elements in two arrays. One of them is an array list full of doubles and the second is a double array full of doubles. I am trying to display the value of the element that they have in common and the element number that it is in.

Here is my code:



Thanks in advance.

Gabe.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couple of really obvious mistakes in your "if" condition...



- An double value (array2[i]), which is a primative, can't be casted to a string.

- The "if" condition is expecting a boolean value (or expression) -- not a Double object.

Henry
 
Gabriel White
Ranch Hand
Posts: 233
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Henry, thanks for the reply.

I have since changed my code. I did know about the casting the primitive type, but now I can get it to run, but it is all wrong.

Here is my resulting code looking for an indexOf in the Arraylist.

 
Stephen Foy
Ranch Hand
Posts: 143
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Gabriel White
Ranch Hand
Posts: 233
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve, but still double is required on indicated line in code:

 
Garrett Rowe
Ranch Hand
Posts: 1296
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could turn your array into a List<Double> using Arrays.asList(), and then call the retainAll() method.
 
Gabriel White
Ranch Hand
Posts: 233
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that my compiler will accept Generics. It says something like requires 1.5, current version 1.2.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.2 is very old(6 or 7 years I think). Is there a reason you are using such an old compiler?
[ April 03, 2006: Message edited by: Rusty Shackleford ]
 
Ken Blair
Ranch Hand
Posts: 1078
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the compiler knows it requires 1.5 I doubt it's actually that old. Perhaps that's just the default target for their IDE or whatever they're using? @OP: Is there any reason you have to compile code with a 1.2 compliance?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic