Home arrow static arrow Java Programming [Archive] - need help with ArrayList or Vector
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - need help with ArrayList or Vector
This topic has 12 replies on 1 page.

Posts:20
Registered: 5/29/04
need help with ArrayList or Vector  
Aug 4, 2004 6:16 AM



 
Anyone know how to make a search in the ArrayList or Vector? i have tried several method available in API ducumentation but it didn't work.
Many thank
 

Posts:1,652
Registered: 8/4/03
Re: need help with ArrayList or Vector  
Aug 4, 2004 6:20 AM (reply 1 of 12)



 
Most of us know at least a couple of ways. Show us what you've done so far and then we can make some recommendations.
 

Posts:105
Registered: 6/8/04
Re: need help with ArrayList or Vector  
Aug 4, 2004 6:21 AM (reply 2 of 12)



 
Well, have you tried the indexOf(Object) method, or lastIndexOf(Object) ?

If you're adding Object of a class you made, make sure that you have the equals() method defined in your class; otherwise, those methods would only find the Objects you're looking for if it's the same Object, rather than identical Objects.
 

Posts:19,725
Registered: 9/26/01
Re: need help with ArrayList or Vector  
Aug 4, 2004 6:21 AM (reply 3 of 12)



 
Jeepers!
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How to ask questions the smart way[/url]
 

Posts:1,652
Registered: 8/4/03
Re: need help with ArrayList or Vector  
Aug 4, 2004 6:24 AM (reply 4 of 12)



 
Holy jumping cats Batman, it's the Jeepers.
 

Posts:24,036
Registered: 2/3/03
Re: need help with ArrayList or Vector  
Aug 4, 2004 6:26 AM (reply 5 of 12)



 
Jeepers!

Schneikies!
 

Posts:105
Registered: 6/8/04
Re: need help with ArrayList or Vector  
Aug 4, 2004 6:28 AM (reply 6 of 12)



 
Jeepers!

Schneikies!

Jinkies!
 

Posts:24,036
Registered: 2/3/03
Re: need help with ArrayList or Vector  
Aug 4, 2004 6:31 AM (reply 7 of 12)



 
Jeepers!

Schneikies!

Jinkies!

Zoiks!
 

Posts:1,652
Registered: 8/4/03
Re: need help with ArrayList or Vector  
Aug 4, 2004 6:32 AM (reply 8 of 12)



 
Jeepers!

Schneikies!

Jinkies!

Zoiks!

Shazam !!!
 

Posts:5,965
Registered: 5/17/03
Re: need help with ArrayList or Vector  
Aug 4, 2004 6:50 AM (reply 9 of 12)



 
i have tried several method available in API
ducumentation but it didn't work.

For a binary search to work the ArrayList or Vector must be sorted.
 

Posts:5,965
Registered: 5/17/03
Re: need help with ArrayList or Vector  
Aug 4, 2004 7:23 AM (reply 10 of 12)



 
.... and for a sort and a binary search to work the class must implement the Comparable interface.
 

Posts:5,965
Registered: 5/17/03
Re: need help with ArrayList or Vector  
Aug 4, 2004 7:26 AM (reply 11 of 12)



 
.... and for all methods of all collections to work properly, the equals and hashCode methods of class Object should be overridden by the class.
 

Posts:37,103
Registered: 3/30/99
Re: need help with ArrayList or Vector  
Aug 4, 2004 7:37 AM (reply 12 of 12)



 
...so if none of that information turns a lightbulb on for you, go back to what the first couple of responses sadi: give more detail about what you want, what you tried, and in what way it "didn't work."
 
This topic has 12 replies on 1 page.