LUKER LUKER - 7 months ago 46
Java Question

ArrayList to String Without the spaces in Android Studio

I am trying to convert this

ArrayList
to a
String
, but don't want the spaces between the numbers. This is what I have so far:

ArrayList<String> arrayList = new ArrayList<String>();

String NumberRightString = "";
String ButtonText = "";

public void OnClick (View v) {

Button button = (Button) v;

String ButtonText = button.getText().toString();

arrayList.add(ButtonText);

StringBuilder sb = new StringBuilder();

for (Object obj : arrayList) {
sb.append(obj.toString());
sb.append("\t");
}

String NumString = sb.toString();

NumString.replaceAll("//s","");

textView.setText(NumString + "/" + number);
}


This does not work and the spaces are still there. Please help me!

Answer

Try to replace

NumString.replaceAll("//s","");

to

NumString = NumString.replaceAll("\\s","");