search Map Ignore Case - Java Collection Framework

Java examples for Collection Framework:Map

Description

search Map Ignore Case

Demo Code


//package com.java2s;

import java.util.Iterator;
import java.util.Map;

public class Main {
    public static String searchMapIgnoreCase(Map hm, String searchFor) {

        Iterator i = hm.entrySet().iterator();
        String newName = null;/*from   w  w  w  .j  av  a 2s.c om*/

        while (i.hasNext()) {

            Map.Entry entry = (Map.Entry) i.next();
            String key = (String) entry.getKey();
            String value = (String) entry.getValue();

            if (key.equalsIgnoreCase(searchFor))
                newName = value;

            if (value.equalsIgnoreCase(searchFor))
                newName = key;

        }

        return newName;
    }
}

Related Tutorials