Use String.trim()
method to get rid of whitespaces (spaces, new lines etc.) from the beginning and end of the string.
String trimmedString = myString.trim();
More Related Contents:
- Need some advice on split() method in Java [closed]
- How to add to string number and keep string in Java?
- Why is char[] preferred over String for passwords?
- Split string with dot as delimiter
- What is the easiest/best/most correct way to iterate through the characters of a string in Java?
- Is there a way to instantiate a class by name in Java?
- Check if String contains only letters
- Is it good practice to use java.lang.String.intern()?
- Check string for palindrome
- Test if a string contains any of the strings from an array
- Is String Literal Pool a collection of references to the String Object, Or a collection of Objects
- The most sophisticated way for creating comma-separated Strings from a Collection/Array/List?
- How much memory does a string use in Java 8?
- How to replace a String in java which contains dot?
- Convert binary string to byte array
- String concatenation complexity in C++ and Java [duplicate]
- What is the best way to extract the first word from a string in Java?
- How to replace ” \ ” with ” \\ ” in java
- Validate a file name on Windows
- Print out elements from an Array with a Comma between the elements
- The split() method in Java does not work on a dot (.) [duplicate]
- How to prevent java.lang.String.split() from creating a leading empty string?
- Efficient way to compare version strings in Java [duplicate]
- How do I apply the for-each loop to every character in a String?
- Java: how to initialize String[]?
- Quotation marks inside a string [duplicate]
- Java – How to visually center a specific string (not just a font) in a rectangle
- Parse Date from String in this format : dd/MM/yyyy [to dd/MM/yyyy]
- How can I print a string adding newlines in Java?
- How many Java objects are generated by this – new String(“abcd”)