Convert java Map to custom key=value string

前端 未结 4 1300
感动是毒
感动是毒 2021-02-13 04:16

I have TreeMap which I need to convert to URI-like string and then back to Map. I need to set custom delimiters.

Is there any tool (Gu

4条回答
  •  有刺的猬
    2021-02-13 04:48

    In java 8 and up there is another way without external dependencies: use StringJoiner:

        List cities = Arrays.asList("Milan", 
                                            "London", 
                                            "New York", 
                                            "San Francisco");
    
        String citiesCommaSeparated = String.join(",", cities);
    
        System.out.println(citiesCommaSeparated);
    
    
        //Output: Milan,London,New York,San Francisco
    

    Credits and example go to this URL (https://reversecoding.net/java-8-convert-list-string-comma/)

提交回复
热议问题