How to append the first N characters from a string to StringBuilder in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "programming java";
 
        StringBuilder sb = new StringBuilder();

        int N = 3;
        sb.append(s, 0, N);
        
        System.out.println(sb);
    }
}
 
 
 
/*
run:
 
pro
 
*/

 



answered Oct 30, 2020 by avibootz

Related questions

1 answer 155 views
1 answer 125 views
1 answer 84 views
...