top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

0 votes
675 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
...