String to HashMap JAVA

后端 未结 10 1337
我寻月下人不归
我寻月下人不归 2020-12-02 11:32

I have a Java Property file and there is a KEY as ORDER. So I retrieve the VALUE of that KEY using the getProperty(

10条回答
  •  醉酒成梦
    2020-12-02 12:00

    Use the String.split() method with the , separator to get the list of pairs. Iterate the pairs and use split() again with the : separator to get the key and value for each pair.

    Map myMap = new HashMap();
    String s = "SALES:0,SALE_PRODUCTS:1,EXPENSES:2,EXPENSES_ITEMS:3";
    String[] pairs = s.split(",");
    for (int i=0;i

提交回复
热议问题