Java HashMap in methods -



Java HashMap in methods -

is possible have method requiring hashmap , able provide hashmap strings keys? kind of generic info type set instead of 'value'?

public void example(hashmap<string, value> hashmap) { //stuff } example(new hashmap<string, integer>); hashmap<string, string> examplemap = new hashmap<>(); example(examplemap);

alternatively, possible check key/value type of map, other looping through keys/value , check instanceof (without stopping return)?

public boolean example(hashmap<string, value> hashmap) { (value value : hashmap.values())) { if (value instanceof string) { homecoming true; //<- unwanted } } }

edit: allow me explain problem bit further. have method:

public static object geteic(hashmap<string, object> map, string key) { (string keys : map.keyset()) { if (keys.equalsignorecase(key)) { homecoming map.get(keys); } } homecoming null; }

eic stands equalsignorecase. need generic homecoming type well. answers far, , on forehand answers on this!

you do:

hashmap<string, object>

but that's terrible though because end doing instanceof time. need understand key problem , think of inheritance. can define interface value objects implement? instance geometricshape implemented rectangle , circle.

also, can define hashmap follows:

hashmap<string, ? extends someclass>

and others pointed out, it's best utilize interface map rather specific implementation e.g. hashmap.

lastly, pointed out in comment, seems trying implement map<key, value> want have case-insensitive keys. if have @ www.stackoverflow.com/questions/8236945/

java hashmap

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -