Below are the various methods to convert an Array to String in Java:
- Arrays.toString() method: Arrays.toString() method is used to return a string representation of the contents of the specified array. The string representation consists of a list of the arrayâs elements, enclosed in square brackets (â[]â). Adjacent elements are separated by the characters â, â (a comma followed by a space). It returns ânullâ if the array is null.
// Java program to demonstrate// working of Arrays.toString()importjava.io.*;importjava.util.*;classGFG {publicstaticvoidmain(String[] args){// Let us create different types of arrays and// print their contents using Arrays.toString()boolean[] boolArr=newboolean[] {true,true,false,true};char[] charArr=newchar[] {'g','e','e','k','s'};double[] dblArr=newdouble[] {1,2,3,4};int[] intArr=newint[] {1,2,3,4};Object[] objArr=newObject[] {1,2,3,4};System.out.println("Boolean Array: "+ Arrays.toString(boolArr));System.out.println("Character Array: "+ Arrays.toString(charArr));System.out.println("Double Array: "+ Arrays.toString(dblArr));System.out.println("Integer Array: "+ Arrays.toString(intArr));System.out.println("Object Array: "+ Arrays.toString(objArr));}}chevron_rightfilter_noneOutput:Boolean Array: [true, true, false, true] Character Array: [g, e, e, k, s] Double Array: [1.0, 2.0, 3.0, 4.0] Integer Array: [1, 2, 3, 4] Object Array: [1, 2, 3, 4]
- StringBuilder append(char[]): The java.lang.StringBuilder.append(char[]) is the inbuilt method which appends the string representation of the char array argument to this StringBuilder sequence.
// Java program to illustrate the// StringBuilder.append(char[]) methodimportjava.lang.*;publicclassGeeks {publicstaticvoidmain(String[] args){StringBuilder sbf=newStringBuilder("We are geeks ");System.out.println(sbf);// Char arraychar[] astr=newchar[] {'G','E','E','k','S'};// Appends string representation of char// array to this String Buildersbf.append(astr);System.out.println("Result after"+" appending = "+ sbf);sbf =newStringBuilder("We are -");System.out.println(sbf);// Char arrayastr =newchar[] {'a','b','c','d'};/* Appends string representation of chararray to this StringBuilder */sbf.append(astr);System.out.println("Result after appending = "+ sbf);}}chevron_rightfilter_noneOutput:We are geeks Result after appending = We are geeks GEEkS We are - Result after appending = We are -abcd
Attention reader! Donât stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- Convert Set of String to Array of String in Java
- Convert an ArrayList of String to a String array in Java
- Convert a Set of String to a comma separated String in Java
- Convert a List of String to a comma separated String in Java
- Convert a String to Character array in Java
- Convert Character Array To String In Java
- Program to convert List of Integer to List of String in Java
- Program to Convert Set of Integer to Set of String in Java
- Program to convert set of String to set of Integer in Java
- Program to convert List of String to List of Integer in Java
- Convert List of Characters to String in Java
- Program to convert IntStream to String in Java
- Program to convert String to IntStream in Java
- Convert a String to a List of Characters in Java
- Convert String to Date in Java
- Convert String to Double in Java
- Convert String into comma separated List in Java
- Convert Java Object to Json String using GSON
- Convert Json String to Java Object Using GSON
- How to convert a String to an Int in Java?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

