top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How many ways we can create the string object in java?

0 votes
62 views
How many ways we can create the string object in java?
posted Jan 25, 2018 by Jon Deck

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

There are various ways you can create a String Object in Java:

Using String literal
You can create String objects with String literal

String str="Hello!";

Using new keyword
This is the common way to create a String object in java

String str1= new String("Hello!");

Using character array
You could also convert character array into String here

char ch[]={ 'H','e','l','l','o','!',};
String str1=new String(ch);
answer Feb 5, 2018 by Ammy Jack
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...