aspose file tools*
The moose likes Beginning Java and the fly likes need help sorting Integer objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help sorting Integer objects" Watch "need help sorting Integer objects" New topic
Author

need help sorting Integer objects

Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
I'm trying to run a selection sort method on a Vector array of Integer objects. Does Integer autoboxing apply in the following code, as I have written it?

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I presume it does, if the compiler doesn't complain. May I attempt to answer your other question by pointing out that (unlike arrays), when you insert something into a Vector, the index of all entries after the inserted entry gets increased by 1? I found it hard to get that right when I tried sorting-like activities on Lists.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Yup, take a look at the API for insertElementAt (better: add(index, object)) versus set(index, object):

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Vector.html


There is no emoticon for what I am feeling!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Better yet, take a look at the static method java.util.Collections.sort().


[Jess in Action][AskingGoodQuestions]
Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
thanks all.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help sorting Integer objects