Skip to content
Advertisement

Tag: space

Adding whitespace in Java

There is a class trim() to remove white spaces, how about adding/padding? Note: ” ” is not the solution. Answer I think you are talking about padding strings with spaces. One way to do this is with string format codes. For example, if you want to pad a string to a certain length with spaces, use something like this: In

How can I find whitespace in a String?

How can I check to see if a String contains a whitespace character, an empty space or ” “. If possible, please provide a Java example. For example: String = “test word”; Answer For checking if a string contains whitespace use a Matcher and call its find method. If you want to check if it only consists of whitespace then

Advertisement