I have a JSON Array string like [1,2].I want to convert this in to Set.How can I do it in java 8 ?
This is my code
String languageStr = rs.getString("languages");
jobseeker.setLanguageIds(StringUtils.isEmpty(languageStr) ? null
: Arrays.stream(languageStr.split(","))
.map(Integer::parseInt)
.collect(Collectors.toSet()));
Getting error like this
java.lang.NumberFormatException: For input string: " 2"
The space in json array is the problem.Is there any solution?
This is my code after changes
String languageStr = rs.getString("languages");
String languages=languageStr.substring(1,languageStr.length()-1);
jobseeker.setLanguageIds(StringUtils.isEmpty(languages) ? null
: Arrays.stream(languages.split(","))
.map(String::trim)
.map(Integer::parseInt)
.collect(Collectors.toSet()));
Can I get the output in any other way withot using these 2 steps: languages=languageStr.substring(1,languageStr.length()-1);
.map(String::trim)