Unless Splitter is doing any magic, the getTokenizeString method is obsolete here. You can perform the entire processing as a single operation:

Map<String,String> map = Pattern.compile("\\s*-\\s*")
    .splitAsStream(responseString.trim())
    .map(s -> s.split("~", 2))
    .collect(Collectors.toMap(a -> a[0], a -> a.length>1? a[1]: ""));

By using the regular expression \s*-\s* as separator, you are considering white-space as part of the separator, hence implicitly trimming the entries. There’s only one initial trim operation before processing the entries, to ensure that there is no white-space before the first or after the last entry.

Then, simply split the entries in a map step before collecting into a Map.

Answer from Holger on Stack Overflow
🌐
Coderanch
coderanch.com › t › 714600 › java › Splitting-string-Hashmap-Java-Streams
Splitting a string and then to Hashmap using Java 8 Streams (Features new in Java 8 forum at Coderanch)
August 16, 2019 - Line 14 changes the Steam to a Stream<String[]> by correct use of the split() method. If you look here (Java™ Tutorials), you will find that “:” isn't a metacharacter. You were right to start line 16 with .collect(), but that needs an argument. It is usual to pass a Collector reference; the easiest way to get such a reference being this. Note that will give you a Map<K, List<V>>. I don't know whether that is going to help in you current situation, but at least it will include every line.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Split String To Map In Java - Java Code Geeks
April 3, 2024 - In this example, the input string name:John age:30 city:New York is split into key-value pairs using the : delimiter, and then stored in a HashMap. The output displays the resulting key-value map.
🌐
Medium
parathan.medium.com › split-map-a-string-in-java-bdb006ef45f9
Split & Map a String in Java
September 27, 2018 - import java.util.*; public class ...value2;key3=value3";if(gotData == ""){ map = null; }else { for(String keyValue : gotData.split(" *; *")) { String[] key = keyValue.split(" *= *"); map.put(key[0], key[1]); } } Map<String,String> ...
🌐
Baeldung
baeldung.com › home › java › java string › split java string into key-value pairs
Split Java String Into Key-Value Pairs | Baeldung
January 8, 2024 - Let’s take an example: @Test ... keyValueMap.get("city")); } In this example, we use a space as the delimiter to divide the input string into an array of key-value pairs....
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Converting String or String Array to Map in Java - Java Code Geeks
October 10, 2023 - We can also use the String.split() method to convert a string to a map in Java. This involves splitting the input string into tokens based on a delimiter, and then parsing these tokens into key-value pairs. Here is an example:
🌐
Java2s
java2s.com › example › android › java.util › split-string-into-map.html
split string Into Map - Android java.util
import java.net.URL; import java.net.URLDecoder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main{ public static Map<String, String> splitIntoMap(String text, String delimiter, String separator) { HashMap<String, String> ret = new HashMap<String, String>(); String decodedString = ""; try {/*from w w w. ja va2 s.c o m*/ decodedString = URLDecoder.decode(text, "UTF-8"); } catch (Exception e) { } String[] split = decodedString.split(delimiter); for (String string : split) { if (string.contains(separator)) { String[] element = string.split(separator); if (element.length == 2) ret.put(element[0], element[1]); } } return ret; } } Previous ·
🌐
KapreSoft
kapresoft.com › java › 2023 › 05 › 03 › java-string-to-map.html
Java • Converting Strings To Map | KapreSoft
May 3, 2023 - To perform this conversion, we can split the input string into an array of key-value pairs using the delimiter, then split each key-value pair into an array of key and value using another delimiter, such as the equals sign.
Find elsewhere
🌐
YouTube
youtube.com › luke chaffey
split string and store it into HashMap java 8 - YouTube
java: split string and store it into HashMap java 8Thanks for taking the time to learn more. In this video I'll go through your question, provide various ans...
Published: November 22, 2022
Views: 90
🌐
javaspring
javaspring.net › blog › split-string-and-store-it-into-hashmap-java-8
Java 8: Split String and Store in HashMap - Fix Stream Collector Issues with Missing Values — javaspring.net
Example: Keep the Last Occurrence Retain the latest value for duplicate keys: Map<String, String> map = Arrays.stream(input.split("&")) .map(pair -> pair.split("=", 2)) // Split into max 2 parts (handles values with '=') .filter(parts -> ...
🌐
Metamug
metamug.com › article › java › string › java-split-lines-hashmap.html
Java Split Lines to Hashmap
Here we have split the line using the equals operator and used collect function to create the hashmap · stream.map(line-> line.split("=")).collect(Collectors.toMap(a->a[0],a->a[1])); Example: name=John Doe age=32 place=New York ·
🌐
Benchresources
benchresources.net › home › java › java 8 – how to split a string and collect to any collection ?
Java 8 - How to split a String and Collect to any Collection ? - BenchResources.Net
September 28, 2022 - Then map a split-ted String using Stream.map() method to remove white-spaces if any · Collect split-ted String to Set using Stream’s collect() method passing Collectors.toSet() as argument · Finally, iterate & print Set to console using Set.forEach() method ... package in.bench.resourc...
🌐
Baeldung
baeldung.com › home › java › java streams › string operations with java streams
String Operations with Java and Stream API | Baeldung
January 8, 2024 - public static Map<String, String> arrayToMap(String[] arrayOfString) { return Arrays.asList(arrayOfString) .stream() .map(str -> str.split(":")) .collect(toMap(str -> str[0], str -> str[1])); } Here, “:” is the key-value separator for all ...
🌐
DevDreamz
devdreamz.com › question › 810989-java-8-split-string-and-create-map-inside-map
Java 8 Split String and Create Map inside Map - DevDreamz
java-8javasplitjava-stream · You ... this: Map<String, Map<String, String>> result = Arrays.stream(samp.split(",")) .map(i -> i.split("-")) .collect(Collectors.groupingBy(a -> a[0], Collectors.toMap(a -> a[1], a -> a[2]))); First it creates ...