Skip to main content

Search and Sort with Java

Posted by aschunkjava on October 11, 2007 at 11:49 AM PDT

Search and Sort API for Java

While working on some simple applications i realized that there is no standard seaerch and sort API for Java but a lot of books covering Algorithms in Java i.g. "Sedgewicks Algorithm in Java".

However it would be easy to implement common algorithms for basic purposes in Java for instance things like linear search binary search or sorting algorithms like bubble sort, quick sort etc.

While most applications require a special implementation of certain standard algorithms a standard API for algorithms in Java might help in certain common tasks.

Another field of algorithms is hashing and algorithms for Graphs. Most common algorithms on Graphs are documented well and lots of implementations are around there. Again a standard API for Graphs algorithms might help for certain common tasks.

Possible implementation

A possible way to implement search and sort functionlity would be to use an interface like Comparable and Comparator for searching:

public interface Sortable{
  public int sort(Object[] items);

Another way is to use concrete classes:

public class BasicSearch{

public Object linearSearch(Object[] item, Object key){


There are various ways to implement such an API but i think having concrete classes or interfaces is a good way to do it.

So its a question to the community if there is a need for a standard API for searching, sorting and may be Graphs.

Related Topics >>