Home Java Java-conversion Convert Array to String



Convert Array to String
Posted on: August 9, 2007 at 12:00 AM
In this section, you will learn how to convert array to string.

Convert Array to String

     

In this program we have taken an array of type String as "String stringarray[] = {"chandan", " " ,"tamana", " " ,"suman", " " ,"Ravi"};" and to convert it to String we have used "arrayToString(stringarray));" as shown below. Therefore we get the following output.

Here is the code of this program:

import java.util.*;
import java.io.*;
import java.util.Arrays;
import java.lang.String;

public class arraytosting {
  public static void main(String[] args) {
  arraytosting arstr = new arraytosting();
  }

  public arraytosting(){
  String stringarray[] 
{
"chandan"" " ,"tamana"" " ,"suman"" " ,"Ravi"};
  System.out.println("Array Value = " 
+ arrayToString
(stringarray));
  }

  public String arrayToString(String[] stringarray){
  String str = " ";
  for (int i = 0; i < stringarray.length; i++) {
  str = str + stringarray[i];
  }
  return str;
  }
}

Output of the program:

C:\unique>javac arraytosting.java

C:\unique>java arraytosting
Array Value = chandan tamana suman Ravi

C:\unique>

Download this example.

Related Tags for Convert Array to String:
cstringarrayconvertsedtypevisumthistostringshowprogramtoramavisheitusepemaninasmtrososndahowprossukisharayandarstrrtssriringtamthshoavbelostgaprndonogro


More Tutorials from this section

Ask Questions?    Discuss: Convert Array to String   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.