Based on the information provided, here one way to do it. It required both splitting in sections and limiting the size and location of the split.
String data = "created:2022-03-16T07:10:26.135Z,timestamp:2022-03-16T07:10:26.087Z,city:Bangalore,Country:Ind";
Map<String, String> map =
Arrays.stream(data.split(","))
.map(str -> str.split(":", 2))
.collect(Collectors.toMap(a -> a[0], a -> a[1]));
map.entrySet().forEach(System.out::println);
See this code run live at IdeOne.com.
city=Bangalore
created=2022-03-16T07:10:26.135Z
Country=Ind
timestamp=2022-03-16T07:10:26.087Z
As I said in the comments, you can't use a single map because of the duplicate keys. You may want to consider a class as follows to hold the information
class CityData {
private String created; // or a ZonedDateTime instance
private String timeStamp;// or a ZonedDateTime instance
private String city;
private String country;
@Getters and @setters
}
You could then group all the cities for of a given country for which you had data in a map as follows:
Map<String, List<CityData>> where the Key is the country.
createdandtimestamprepeatedly in the same map as duplicate keys are not permitted. How to you plan to handle multiple similar strings in the same map and still keep the proper pairings?very big stringrepresent multiple cities and countries?