I'm currently developing a Translator app using yandex API. Due to some reason the translated output comes with many spaces. For a example if I translate "Always faithful" in to Latin, it show result like " Semper fidelis ". So I wanted to remove these spaces and show it like "Semper fidelis" So I wrote below code (this is written with coma because it's clear to see the idea)
public String modifyString(String tobeModify){ String[] store = tobeModify.split("\\s+"); String output=null; if (store.length == 0){ output = ""; }else if (store.length == 1){ output = store[0]; }else { output = String.join(",", store); } return output; } But this product output like ,Semper,fidelis. Also store array has length 2 as I printed it should be empty string. What I want to print the output like "Semper,fidelis" (coma is for demonstration purposes). I can't find out what's wrong here