General k search in java implemented