View RSS Feed

Java String

Creating Strings

Rate this Entry
by , 04-26-2012 at 07:25 PM (330 Views)
Another direct method for creation of string is, to write:
Java Code:
String greeting = "Hello world!";
In your code, whenever string literal is encountered, a String object is created by the compiler along with value, “Hello World”
Eleven constructors are present in String class which permits to give the string’s initial value by usage of different kind of resources, like character array.
Java Code:
public class StringDemo{
   public static void main(String args[]){
      char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'};
      String helloString = new String(helloArray);  
      System.out.println( helloString );
Result would be:

Submit "Creating Strings" to Facebook Submit "Creating Strings" to Digg Submit "Creating Strings" to Submit "Creating Strings" to StumbleUpon Submit "Creating Strings" to Google