Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

import android.content.Context;

public class Main {
    /**
     * Parse a string-array resource with items like this: <item>key|value</item>
     * @param ctx
     * @param stringArrayResourceId
     * @return the keys=>values as an HashMap
     */
    public static HashMap<String, String> parseStringMapResource(Context ctx, int stringArrayResourceId) {
        String[] stringArray = ctx.getResources().getStringArray(stringArrayResourceId);
        HashMap<String, String> map = new HashMap<String, String>(stringArray.length);
        for (String entry : stringArray) {
            String[] splitResult = entry.split("\\|", 2);
            map.put(splitResult[0], splitResult[1]);
        }
        return map;
    }
}