Wednesday, 4 January 2017

What are different ways to create String Object ?

There are two ways to create String Objects in Java.
1 ) by using String Literal
String s1 = "abc";

2 ) by using new operator
String s2 = new String("abc");

Example :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
public class WaysToCreateStringObject {
 
 public static void main(String[] args) {
  
  //String creation using String literal
  String s1 = "abc";
  
  //String creation using new operator
  String s2 = new String("abc");
 }
}


      
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



Share this Blog with yours Friends !!

No comments:

Post a Comment