Thursday, 17 October 2013

java handling string and splitting it in key-value



public class StringSplit {
            public static void main(String[] args) {

                        String assetClasses = "name = Gold: price = Stocks:icome = Fixed :********";
                        assetClasses.replace("*", "");
                        String[] splits = assetClasses.split(":");
                        HashMap<String, String> hash = new HashMap<String, String>();

                        System.out.println("splits.size: " + splits.length);
                        for (String asset : splits) {
                                    if (asset.indexOf("=") != -1) {
                                                String[] splitstwo = asset.split("=");

                                                //if ((splitstwo.length == 2))
                                                            hash.put(splitstwo[0], splitstwo[1]);

                                                for (String splitasset : splitstwo) {

                                                            System.out.println(splitasset);
                                                }
                                    }
                                    System.out.println(asset);
                                    System.out.println(hash);
                        }

            }

}

No comments:

Post a Comment

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...