Iterate through the array and replace each entry with your encoded version.
So, suppose you are really only looking for URL compatible strings:
for (int index =0; index < test.length; index++){ test[index] = URLEncoder.encode(test[index], "UTF-8"); }
To match current Java, you must specify an encoding — however, it must always be UTF-8 .
If you want a more general version, do what everyone else offers:
for (int index =0; index < test.length; index++){ test[index] = test[index].replace(" ", "%20"); }
source share