I have a requirement to read the string from a list and join them with ','. Also need to add comma in prefix and suffix of the total output string. Example : If list contans["a","b","c"] then output would be ",a,b,c,".
Now thats perfectly working with Collectors.joining but if the list does not contains any value then also in output strting I am getting ",," as output because prefix and suffix is added.
Now what I want is to avoid the prefix and suffix in case if blank String. So, any suggestion?
List<String> list = new ArrayList<>();
String result = list.stream().collect(Collectors.joining(",", ",", ","));
System.out.println(result);
Thanks in Advance.