Solved

sorting

Posted on 2000-05-18
3
209 Views
Last Modified: 2010-04-01
I got problem with sorting an array in java. Can any one give a source code of sorting array in java or referring me to website that i can learn about sorting in java

thanks

0
Comment
Question by:H3R1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Expert Comment

by:ovidiucraciun
ID: 2820192
in package java.util.Arrays you'll find
all support for sorting objects arrays,
look here a single example

"public static void sort(Object[] a)
Sorts the specified array of objects into ascending order, according to the natural ordering of its elements. All elements in the array must implement the Comparable interface. Furthermore, all elements in the array must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the array).
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) performance, and can approach linear performance on nearly sorted lists.

Parameters:
a - the array to be sorted.
Throws:
ClassCastException - if the array contains elements that are not mutually comparable (for example, strings and integers).
See Also:
Comparable"
0
 
LVL 7

Accepted Solution

by:
Ravindra76 earned 100 total points
ID: 2820285
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2821265
Even if you can use the Arrays class (it arrived in Java 2), it might be interesting for you to have a look at the Sorting Algorithms page if you care to learn more about sorting, see some applet demonstrations of various techniques, and/or download the implementations.
    http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html

Best regards,
Jim Cakalic
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question