23 Şubat 2023 Perşembe

String.indent metodu

Giriş
Java 12 ile geliyor. Her satırın başına belirtilen sayı kadar boşluk ekler

Örnek
Şöyle yaparız
String poem = "Two loves I have of comfort and despair,\n" +
                "Which like two spirits do suggest me still:\n" +
                "The better angel is a man right fair,\n" +
                "The worser spirit a woman color’d ill.\n";

System.out.println(poem);
System.out.println(poem.indent(4));
System.out.println(poem.indent(10));


Two loves I have of comfort and despair,
Which like two spirits do suggest me still:
The better angel is a man right fair,
The worser spirit a woman colord ill.

    Two loves I have of comfort and despair,
    Which like two spirits do suggest me still:
    The better angel is a man right fair,
    The worser spirit a woman colord ill.
          
          Two loves I have of comfort and despair,
          Which like two spirits do suggest me still:
          The better angel is a man right fair,
          The worser spirit a woman colord ill.


Hiç yorum yok:

Yorum Gönder