There is a class trim()
to remove white spaces, how about adding/padding?
Note: " "
is not the solution.
This question is related to
java
whitespace
space
trim
spaces
If you have an Instance of the EditText available at the point in your code where you want add whitespace, then this code below will work. There may be some things to consider, for example the code below may trigger any TextWatcher you have set to this EditText, idk for sure, just saying, but this will work when trying to append blank space like this: " ", hasn't worked.
messageInputBox.dispatchKeyEvent(new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_SPACE, 0, 0, 0, 0,
KeyEvent.KEYCODE_ENDCALL));
String text = "text";
text += new String(" ");
Use the StringUtils class, it also includes null check
StringUtils.leftPad(String str, int size)
StringUtils.rightPad(String str, int size)
There's a few approaches for this:
Source: Stackoverflow.com