| Author |
Comparing ArrayList and double array[]
|
Gabriel White
Ranch Hand
Joined: Mar 02, 2003
Posts: 233
|
|
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
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
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
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Gabriel White
Ranch Hand
Joined: Mar 02, 2003
Posts: 233
|
|
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
Joined: Oct 17, 2005
Posts: 143
|
|
|
|
Stephen Foy - Microsoft Application Development Consultant
|
 |
Gabriel White
Ranch Hand
Joined: Mar 02, 2003
Posts: 233
|
|
Thanks Steve, but still double is required on indicated line in code:
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
|
You could turn your array into a List<Double> using Arrays.asList(), and then call the retainAll() method.
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Gabriel White
Ranch Hand
Joined: Mar 02, 2003
Posts: 233
|
|
|
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
Joined: Jan 03, 2006
Posts: 490
|
|
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 ]
|
"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
|
 |
Ken Blair
Ranch Hand
Joined: Jul 15, 2003
Posts: 1078
|
|
|
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?
|
 |
 |
|
|
subject: Comparing ArrayList and double array[]
|
|
|