Split string into key-value pairs

后端 未结 7 1593
青春惊慌失措
青春惊慌失措 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:21

    Try this code - see the comments for an explanation:

    HashMap hmap = new HashMap<>();
    String str="abc:1::xyz:2::jkl:3";
    String straraay[]= str.split("::?");
    
    for(int i=0;i

提交回复
热议问题