This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 19649

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: 37907
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
Similar Threads
arrays merge and sorting
difference between sorting and ordering
Reverse sort of array
duplicate values in sort
collection to string array possible!