aspose file tools
The moose likes Beginning Java and the fly likes Taking an element out of an array Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Taking an element out of an array" Watch "Taking an element out of an array" New topic
Author

Taking an element out of an array

Ron Temple
Greenhorn

Joined: May 02, 2010
Posts: 2
I'm trying to take an animal element of an array for filtering but I'm having some problems. I need to take the element i need out of the array. Then I need to find out whether the animal is the type I need. Finally I need to add the animal object to the array. I have to seperate arrays of displayed animals and all the animals but I'm just having trouble figuring out how to do the above. Any advice is greatly appreciated. Here's what I have so far:



And the entire code:
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm lost: what are you trying to do again?
Allain Walker
Greenhorn

Joined: May 24, 2005
Posts: 14
Hi Ron,
try using

You could even pass the class type into a function and reduce the duplication in the code.
I have come up against this sort of issue before and never really had the time to try to figure out why this is happening. I have always just gone with the isInstance() function instead. If somebody can explain it I would be grateful.

5 years on and still a Greenhorn, what to do, what to do?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@Allain: you're saying instanceOf doesn't work for you?

@Ron: The fragment, and that fragment embedded in the entire code, are not the same. What *is* happening, and what do you *expect* to happen?
Allain Walker
Greenhorn

Joined: May 24, 2005
Posts: 14
Hi David,
What I am saying is that I have tried to use the instanceof before and I must have made a mistake with it, or not understood how it works. At the time instead of using instanceof I used class.isInstance(o) and achieved the outcome I was looking for.
I didn't have time to examine what I was doing wrong, and it fell of the radar. I now have the time to do that now and will try again.
Thanks
Allain
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Taking an element out of an array
 
Similar Threads
Why is not working
Generics.
Generics problem- why not taking Animal, Object and super of Dog
Generics Help please !
Generics Question