Implementation of different data structures in java