Split string into key-value pairs

后端 未结 7 1543
青春惊慌失措
青春惊慌失措 2020-12-31 03:40

I have a string like this:

pet:cat::car:honda::location:Japan::food:sushi

Now : indicates key-value pairs while ::

相关标签:
7条回答
  • 2020-12-31 04:38

    This might be useful. *utm_source=test_source&utm_medium=test_medium&utm_term=test_term& utm_content=test_content&utm_campaign=test_name&referral_code=DASDASDAS

       String str[] = referrerString.split("&");
                        HashMap<String,String> stringStringHashMap= new HashMap<>();
                        List<String> al;
                        al = Arrays.asList(str);
                        String[] strkey ;
    
                    for (String s : al) {
                        strkey= s.split("=");
                        stringStringHashMap.put(strkey[0],strkey[1]);
    
    
                    }
                    for (String s : stringStringHashMap.keySet()) {
                        System.out.println(s + " is " + stringStringHashMap.get(s));
                    }
    
    0 讨论(0)
提交回复
热议问题