wood burning stoves
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
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: 20274

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 http://www.javaranch.com/evenOrOdd.jsp

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: 46367
They ought to be teaching you about sorting. Try here or here.
It is sorta covered in the JavaRanch Style Guide.
subject: sorting of elements in an array
jQuery in Action, 3rd edition