Miscellaneous Java Algorithms

A great benefit of using the Java programming language is the huge class library available. Not only does Sun provide a large class library in their Java SDK (Software Development Kit), but there are extensive, freely available, libraries available from organizations like the Apache Project. If you can find the right class and use it in the correct way, you can avoid writing a great deal of code. But this begs the question... How do you find the right class and how do you understand how to use it, given that the Javadoc documentation is frequently less that complete?

A great reference to answer those "how do I do X in Java" questions is Java Cookbook by Ian F. Darwin. However, as extensive and useful as this book is, there are still algorithms that I have not found in it. Frequently these are just a few lines of code, but many hours can be spent pouring through the documentation and trying out code to find the right solution. Since I hate to do this twice, I've provided a few of these algorithms here.

Ian Kaplan, February 12, 2000
Updated: December, 2005