Pages

Thursday, May 24, 2012

Java - Maps / storing values in key-value pair

        Map<String, Integer> mPair = new HashMap<String, Integer>();       

        mPair.put("one", new Integer(1));
        mPair.put("two", new Integer(2));
        mPair.put("three", new Integer(3));
        System.out.println(mPair.values());

        if (mPair.containsKey("two"))
            System.out.println(mPair.get("two"));

No comments:

Post a Comment