Home> Java> javaTutorial> body text

Convert string to StringBuilder in Java

王林
Release: 2023-09-02 15:57:06
forward
1092 people have browsed it

The

append()Convert string to StringBuilder in Javamethod of the

StringBuilderclass accepts a String value and adds it to the currentobject.

Convert the string value to a StringBuilder object -
  • Get the string value.

  • Append using theappend()method to get the string to the StringBuilder.

Example

In the following Java program, we convert an array of strings into a single StringBuilder object.

Real-time demonstration

public class StringToStringBuilder { public static void main(String args[]) { String strs[] = {"Arshad", "Althamas", "Johar", "Javed", "Raju", "Krishna" }; StringBuilder sb = new StringBuilder(); sb.append(strs[0]); sb.append(" "+strs[1]); sb.append(" "+strs[2]); sb.append(" "+strs[3]); sb.append(" "+strs[4]); sb.append(" "+strs[5]); System.out.println(sb.toString()); } }
Copy after login

Output

Arshad Althamas Johar Javed Raju Krishna
Copy after login

The above is the detailed content of Convert string to StringBuilder in Java. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!