I want to search a hash map depending on the user input. Suppose a user give value 'A',I have to display starting with A company name and if user give value 'AB' I have to display starting with AB company name. I am storing company name in hash map
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Hash maps are only really good at finding exact matches based on some idea of equality which can be appropriately hashed.
Two options:
you should look into regex (regular expressions)
http://download.oracle.com/javase/tutorial/essential/regex/
your company names are Strings then you can use
Use a NavigableSet.
Example:
Use a radix tree [wiki] or trie [wiki] if you are concerned about performance.The radix tree is more memory efficient compared to a trie.
You can loop over the keyset and check each key. For example:
Or, you can loop over the entries in the map.