Posts

Showing posts with the label hashmap

Find numbers which begins with a given number in a Map in Java

Find numbers which begins with a given number in a Map in Java I'd like to count all keys in a HashMap which begin with a given number. The size of each key is not always the same. Example: given number(long): long l = 9988776655 find the keys (long) which begin with that number like: 9988776655xxxxxxxxxxxxxxx in which x stands for any integer. How do I approach this problem? Since the length of the keys is not always the same I cannot do it with multiple modulo operations. (or can I?) String.valueOf(veryLongNumber).startsWith(String.valueOf(smallerNumber)) – Lino Jun 29 at 11:10 String.valueOf(veryLongNumber).startsWith(String.valueOf(smallerNumber)) Thanks for the quick answer! – notsosmart.nk Jun 29 at 11:13 ...