aspose file tools*
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
Author

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
Sheriff

Joined: Oct 27, 2005
Posts: 19695
    
  20

Is this a homework assignment or not?

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
They ought to be teaching you about sorting. Try here or here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sorting of elements in an array