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 sorting of elements in an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sorting of elements in an array" Watch "sorting of elements in an array" New topic

sorting of elements in an array

yekkala krishna
Ranch Hand

Joined: Mar 04, 2007
Posts: 105
Hi this is Y.Rama Krishna.i have small problem regarding sorting of an array.
i have an array like :
int a[]={1,2,3,1,2,3,1,2,3,1,2,3};
This array i have to sort like {1,1,1,1,2,2,2,2,3,3,3,3}
How i can sort the elements in this order.
Thanks in advance.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20193

Is this a homework assignment or not?

If not, check class java.util.Arrays. It has some methods for sorting different types of arrays.

How To Ask Questions How To Answer Questions
Stuart Smith
Ranch Hand

Joined: Mar 28, 2008
Posts: 54
You can use modulo to determine if a number is odd or even take a look a

Having trouble with arrays my self so can't offer any help with that part.

Dale Carnegie:<br />"Most of the important things in the world have been accomplished<br />by people who have kept on trying when there seemed to be no hope at all."
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45359
They ought to be teaching you about sorting. Try here or here.
I agree. Here's the link:
subject: sorting of elements in an array
It's not a secret anymore!