next Line in StringBuilder - Java java.lang

Java examples for java.lang:StringBuilder

Description

next Line in StringBuilder

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        StringBuilder sb = new StringBuilder();
        System.out.println(nextLine(sb));
    }/*www .  j a v  a  2 s.c om*/

    public static String nextLine(StringBuilder sb) {
        int index = sb.indexOf("\r\n");
        String line;

        if (index < 0) {
            if (sb.equals(""))
                return null;
            else {
                line = sb.toString();
                sb.delete(0, sb.length()); // ?
            }
        } else {
            line = sb.substring(0, index);
            sb.delete(0, index + 2);
        }
        return line;
    }
}

Related Tutorials