0

I have some key/value pairs stored in a HashMap. Key/Value pairs are given like this: "firstKey,secondKey=value". For example: "9,6=3" The maximum value of "value" is 5. I want to check if keys contain one of the values and then save the key as an int and pass it as an argument to another method. Is there any proper method to differentiate/split the key? Or any other way to make this method work? Thank you!

public static HashMap<String, String> h = new HashMap<>();

    Enumeration<?> e = p.keys();
    while (e.hasMoreElements())
    {
        String key = (String) e.nextElement();
        String value = p.getProperty(key);
        h.put(key, value);
        for (int i=0; i<h.size(); i++)
        {
            if (h.containsValue("0"))
            {
                String [] keys = key.split(",");
                for (String key1 : keys)
                {
                    part1 = keys[0];
                    part2 = keys[1];
                    int firstKey = Integer.parseInt(part1);
                    int secondKey = Integer.parseInt(part2);
                    t.moveCursor(firstKey, secondKey);
                    t.applyForegroundColor(RED);
            }
        }
Xhens
  • 804
  • 3
  • 13
  • 33
  • 2
    Don't use a `HashMap` as you're asking String to take the place of an object, to do too much. Instead your first Key should be a new type that holds two ints, that has HashCode and equals overridden. For example, `HashMap`. This will make your work a **lot** easier to do I think. – Hovercraft Full Of Eels Jan 16 '15 at 01:09
  • 1
    Even better are the suggestions in @qqibrow's links. But regardless and as the answers in that link reinforce, it's a bad "anti"-pattern to force Strings to take on this responsibility. – Hovercraft Full Of Eels Jan 16 '15 at 01:11

0 Answers0