Adjust Indentation

Java-Adjust Indentation

Adjust Indentation

The intent( ) method of Stirng is used to adjust the indentation of each line of this string based on the specified value, and normalizes line termination characters. If value is 5 then 5 spaces (U+0020) are inserted at the beginning of each line. For example:

Adjust Indentation

If value is -5 then up to 5 white space characters are removed from the beginning of each line. If a given line does not contain sufficient white space then all leading white space characters are removed. Each white space character is treated as a single character. For example:

Adjust Indentation


In particular, the tab character “\t” (U+0009) is considered a single character; it is not expanded. If value is 0 then the line remains unchanged. However, line terminators are still normalized. For example:

Adjust Indentation

Program

Adjust Indentation


Program Source

public class Javaapp {

    public static void main(String[] args) {

        String str = "ABC\nDEF\nGHI";
        String str2 = str.indent(5);
        System.out.println("<--->");
        System.out.println(str2+"<--->");
    }
}

Leave a Comment