In java, what's the best way to read a url and split it into its parts?

前端 未结 4 1000
攒了一身酷
攒了一身酷 2021-01-18 01:27

Firstly, I am aware that there are other posts similar, but since mine is using a URL and I am not always sure what my delimiter will be, I feel that I am alright posting my

4条回答
  •  感情败类
    2021-01-18 02:13

    you can use String class split() and store the result into the String array then iterate the array and store the variable and value into the Map.

    public class URLSPlit {
        public static Map splitString(String s) {
            String[] split = s.split("[= & ?]+");
            int length = split.length;
            Map maps = new HashMap<>();
    
            for (int i=0; i newmap =  splitString(word);
    
            for(Map.Entry map: newmap.entrySet()){
                System.out.println(map.getKey()+"  =  "+map.getValue());
            }
        }
    }
    

提交回复
热议问题