Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Finding the closest value to a given number in a collection object

807591Mar 27 2008 — edited Mar 28 2008
Hi,

How do i find the closest values in a vector or hashtable, to a given number.

example:
let's say a vector or hashtable contains these numbers:
1562221
1981112
2654489
3023121
3506652
4022258

if i pass the number "1562230" to a method it should return the number "1562221" and "1981112" (which are the closest numbers).

Note:
Actually each number in vector are large numbers(ranging from 8 to 9 digits). so i think finding the closest value by incrementing or decrementing will take a lot of time.
Is there any easier method to find it ?

Thanx in advance :-)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2008
Added on Mar 27 2008
3 comments
427 views