How to get a substring from StringBuilder() in Java

1 Answer

0 votes
package javaapplication1;

import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        StringBuilder sb = new StringBuilder();
        sb.append("java");

        String s = sb.substring(2);
        System.out.println(s);

        s = sb.substring(0, 2);
        System.out.println(s);
    }
}


/*

run:
                   
va
ja
          
 */

 



answered Dec 19, 2016 by avibootz
edited Jan 10, 2017 by avibootz

Related questions

1 answer 133 views
1 answer 138 views
1 answer 155 views
1 answer 119 views
1 answer 116 views
...