How to append substring from String to StringBuilder in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            StringBuilder sb = new StringBuilder();
            String s = "java programming";

            sb.append(s, 0, 4);
            System.out.println(sb);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
             
run:

java
    
 */

 



answered Nov 26, 2016 by avibootz

Related questions

1 answer 153 views
1 answer 162 views
1 answer 119 views
...