Search code examples
javahashmapcomparison

Comparing two hash-maps and printing intersections


I have two hash maps: one contains an Integer key and String value.

The other contains an Integer key and float value.

Code

Map<Integer,String> mapA = new HashMap<>();
mapA.put(1, "AS");
mapA.put(2, "Wf");

Map<Integer,Float> mapB = new HashMap<>();
mapB.put(2, 5.0f);
mapB.put(3, 9.0f);

My question is how to compare the two hash maps using the integer key value? I want to print the bitmap value when the key values are the same.


Solution

  • yes i got solution...

     if(mapB.containsKey(position)){
              Log.e("bucky",mapB.get(position));}
    

    position means integer value.