Pages

Get String from char array

Complete source code below will show you, how to get String from char array.

***********************************************************************
COMPLETE SOURCE CODE FOR : GetStringFromCharArray.java
***********************************************************************


public class GetStringFromCharArray
{
public static void main(String[]args)
{
//Create an array from char type that will store all character for a String
char[]allCharacter=new char[12];

//Set all value in created array
allCharacter[0]='H';
allCharacter[1]='e';
allCharacter[2]='l';
allCharacter[3]='l';
allCharacter[4]='o';
allCharacter[5]=' ';
allCharacter[6]='W';
allCharacter[7]='o';
allCharacter[8]='r';
allCharacter[9]='l';
allCharacter[10]='d';
allCharacter[11]='!';

//Get String from created char array
String resultString=new String(allCharacter);

//Print result
System.out.println(resultString);
}
}


***********************************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************************
Related Posts Plugin for WordPress, Blogger...