Java String to Map StringToMap(String str)

Here you can find the source of StringToMap(String str)

Description

String To Map

License

Open Source License

Declaration

public static HashMap<String, String> StringToMap(String str) 

Method Source Code

//package com.java2s;
//   Licensed under the Apache License, Version 2.0 (the "License"); you may

import java.util.HashMap;

public class Main {
    public static HashMap<String, String> StringToMap(String str) {
        return StringToMap(str, "\\n", "=");
    }//w w w.  ja  v a 2s.c  om

    public static HashMap<String, String> StringToMap(String str, String outter, String inner) {
        //chop the string into tokens using the outter delimiter first, typically \n
        String[] tokens = str.split(outter);
        HashMap<String, String> map = new HashMap<String, String>();
        for (int i = 0; i < tokens.length; i++) {
            //skip comments
            if (tokens[i].startsWith(";"))
                continue;

            //chop the string further by inner delimiter, typically =
            String[] strings = tokens[i].split(inner);
            if (strings.length == 2)
                map.put(strings[0], strings[1]);
        }

        return map;
    }
}

Related

  1. stringToMap(final String s)
  2. stringToMap(String append)
  3. stringToMap(String source, String delimiter)
  4. stringToMap(String src)
  5. stringToMap(String src)
  6. stringToMap(String str)
  7. stringToMap(String value)
  8. stringToMap(String[] strings)
  9. toMap(String componentName, String contextName)