File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help sorting Integer objects" Watch "need help sorting Integer objects" New topic

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

Joined: Oct 14, 2005
Posts: 19693

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):

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

Joined: Jul 08, 2003
Posts: 24189

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:
subject: need help sorting Integer objects
It's not a secret anymore!