What does \n\r\t\f mean

1. \n Newline to position the cursor on the next line

public class Test {
	public static void main(String[] args) {
		System.out.print("aaaaaaaaaaaaa\nbbbb"); }}Copy the code

Results:

2. \r Return character to return the cursor to the beginning of the current line. If there was content in the previous line, it will be overwritten;

public class Test {
	public static void main(String[] args) {
		System.out.println("hello world\r12345"); }}Copy the code

Results:



Description:

In this case, it looks like printing 1234 after the previous output of Hello World has been emptied.

In the console, however, its output is what we expect:



As for the reason, it must be related to the compiler.

3. \t is a TAB character. That’s TAB indent.

Fill in the space so that your output is a multiple of 4

public class Test {
	public static void main(String[] args) {
		System.out.println("a\t*");
		System.out.println("123412341234");
		System.out.println("aaa\t*");
		System.out.println("123412341234");
		System.out.println("aaaa\t*");
		System.out.println("123412341234");
		System.out.println("aaaaa\t*");
		System.out.println("123412341234"); }}Copy the code

Results:

4. \f is a page-feed character and does not make sense on the console.

public class Test {
	public static void main(String[] args) {
		System.out.println("aaaa\fbbbb"); }}Copy the code

Results:

Convert the text with these delimiters to a List

public class Test{
    public static void main(String[] args){
        String content = "a b\tc\nd\re\ff,g";
        // Take field values (acceptable separators are Spaces, tabs, line feeds, carriage returns, page feeds, and English commas)
        StringTokenizer st = new StringTokenizer(content, " \t\n\r\f,");
        List<String> values = new ArrayList<String>();
        while (st.hasMoreElements()) {
            String value = st.nextToken();
            if(StrUtil.isNotBlank(value)){ values.add(value.toUpperCase()); } } System.out.println(values); }}Copy the code

Results:

Reference:

Java \n\r\t\f difference