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

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

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

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.
Consider Paul's rocket mass heater.
subject: need help sorting Integer objects
Similar Threads
Trouble comparing fractions
ArrayList Manipulation
sorting fractions problem
static final int[] wont print unsorted column
; expected