-1

I am storing the result of list<Object[]> into a set as shown below..

String s ;

for (Object[] arr : ilist) {
    String t = arr[2].toString();
    Set<String> st = new HashSet<String>();
    s=((String) arr[0]+ (String) arr[1]+t + (String) arr[3]);
}

now the problem is that upon debugging i found that in arr[2] the value is "TRE RTYU" that is a string but as we can see that there are space in between please advise how can i remove the space in between so that the value in arr[2] = "TRERTYU"

songyuanyao
  • 169,198
  • 16
  • 310
  • 405
  • 3
    [How to remove space from string in java](https://www.google.co.in/search?q=how+to+remove+space+from+string+in+java&aq=0&oq=how+to+remove+space+from+&aqs=chrome.1.57j0l3j62l2.6990j0&sourceid=chrome&ie=UTF-8)...Have you tried to search once ? – Not a bug Apr 26 '14 at 12:43
  • possible duplicate of [Removing whitespace from strings in Java](http://stackoverflow.com/questions/5455794/removing-whitespace-from-strings-in-java) – Not a bug Apr 26 '14 at 12:46

2 Answers2

1

try this:

arr[2].toString().replaceAll("\\s+","");
1
s=((String) arr[0]+ (String) arr[1]+t + (String) arr[3]);
s = s.replaceAll(" ", "");
Dig
  • 254
  • 1
  • 9