How to get the key from Trove TIntObjectHashMap for a value that exists and been found in the map ??
if(map.containsValue(source)) {
for (Entry<Integer, String> entry : map.entrySet()) { // entrySet() is not recognized by Trove? and i can not find any corresponding method ??
if (entry.getValue().equals(source)) {
entry.getKey();
}
}
}
I would do something like this:
TIntObjectMap<String> map = new TIntObjectHashMap<>();
map.put( 1, "a" );
map.put( 2, "b" );
AtomicInteger found = new AtomicInteger( -1 );
map.forEachEntry( new TIntObjectProcedure<String>() {
@Override
public boolean execute( int key, String value ) {
if ( value.equals( "a" ) ) {
found.set( key );
return false;
}
return true;
}
} );
System.out.println( "Found: " + found.get() );
Things to remember: