This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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.
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
Joined: Jul 15, 2001
Thanks all for your replies and the time spent on them. The information provided was exactly what I need!