File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Alphabetic Sorting in various data structures. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Alphabetic Sorting in various data structures." Watch "Alphabetic Sorting in various data structures." New topic
Author

Alphabetic Sorting in various data structures.

Reid Hattaway
Greenhorn

Joined: Jul 15, 2001
Posts: 7
I've done most of my programming in C++ and Python and I have been impressed w/ all of the built in classes and methods of Java as I have started to learn it. However, I can't seem to find the function or functions that I need to finish my task. I would like to be able to sort Strings, Vectors, or Arrays into alphabetical order (w/o having to write my own functions!). Given a string "ABCA", i would like the function to return a new string "AABC". Given a vector or array of Strings, i would like the function to alter the same array or vector so that its components are sorted by their String values. Is this possible, or do I need to write this function?
I would also like to know if Java has any pre-built algorithms such as a Binary Search.
I do not have a Java book yet, so I only have Sun's online documentation.
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
Hi, Reid.
I ran across this page, which says:

Sort a String array

Sort utilities are now part of latest JDK versions.
Case sensitive:
java.util.Arrays.sort(myArray);

Case insensitive:
java.util.Arrays.sort(myArray, String.CASE_INSENSITIVE_ORDER);

Hope this helps,
Art
Detlev Beutner
Ranch Hand

Joined: Jul 13, 2001
Posts: 76
Reid:
1.) About the algorithms:
On all Collections (the most important: ArrayList & Vector, but there are more), you have implemented the following algorithms: sort, binarySearch, reverse, shuffle, fill, copy, min, max. These are static methods in the Collections.class (which just offers these algorithms on Collections).
2.) About the sorting of a String:
String are /not/ implemented as an array of chars. /But/ they are somehow equivalent, so you can convert a string to an array of chars and vice versa. With this, you have the following solution on your problem:

All this can be found in the API Specification (you can use the online-search at sun!).
Hope it helps
Detlev
Reid Hattaway
Greenhorn

Joined: Jul 15, 2001
Posts: 7
Thanks all for your replies and the time spent on them. The information provided was exactly what I need!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Alphabetic Sorting in various data structures.
 
Similar Threads
How to write retrieved data into javascript Array?
isNaN function
Dynamic data class
NOT an array of pointers
Use a JSP variable in JavaScript? Plz Help