How to append a newline to StringBuilder

前端 未结 8 665
天涯浪人
天涯浪人 2020-12-04 06:37

I have a StringBuilder object,

StringBuilder result = new StringBuilder();
result.append(someChar);

Now I want to append a newline characte

8条回答
  •  渐次进展
    2020-12-04 07:22

    It should be

    r.append("\n");
    

    But I recommend you to do as below,

    r.append(System.getProperty("line.separator"));
    

    System.getProperty("line.separator") gives you system-dependent newline in java. Also from Java 7 there's a method that returns the value directly: System.lineSeparator()

提交回复
热议问题