System.out.println("I\nam\na\nboy");
System.out.println("I am a boy".replaceAll("\\s+","\n"));
System.out.println("I am a boy".replaceAll("\\s+",System.getProperty("line.separator"))); // portable way
More Related Contents:
- How to remove line breaks from a file in Java?
- Strings written to file do not preserve line breaks
- Problems with newline in Graphics2D.drawString
- StringBuilder vs String concatenation in toString() in Java
- How do I convert from int to String?
- Sort on a string that may contain a number
- String’s Maximum length in Java – calling length() method
- How to convert comma-separated String to List?
- String Constant Pool
- How to split a comma-separated string?
- Java, Calculate the number of days between two dates [duplicate]
- length and length() in Java
- How to format a Java string with leading zero?
- Convert array of strings into a string in Java
- Should I use string.isEmpty() or “”.equals(string)?
- How to insert a character in a string at a certain position?
- Convert seconds value to hours minutes seconds?
- Understanding logic in CaseInsensitiveComparator
- Convert String to int array in java
- How to shuffle characters in a string without using Collections.shuffle(…)?
- Closing a Scanner throws java.util.NoSuchElementException
- Which loop has better performance? Why?
- Is conversion to String using (“” + ) bad practice?
- Java split is eating my characters
- Java. Ignore accents when comparing strings
- How can I left-align strings using String.format()?
- Case insensitive matching in Java switch-case statement
- How many Java string objects created in the code String s=”abc”+”xyz”;?
- How String Literal Pool Works
- Java replace all square brackets in a string