Java string declarations

Atreyo Bhattacharjee

Commendable
Feb 7, 2017
42
0
1,580
0
Just out of curiosity, why can we declare Strings in Java like:

Java:
String str = "Cake";
If String is a class, and to make an object with all other classes we need to write something like:

Java:
Object muffin = new Object();
 

Brian28

Estimable
Jan 28, 2016
1
0
4,520
1
Because when they wrote the specs, they wanted to define String constants even though String is not a primitive. Nobody would want to use Java if you had to write
String str = new String(new char[] {'C','a','k,'e'});
 

Brian28

Estimable
Jan 28, 2016
1
0
4,520
1
Because when they wrote the specs, they wanted to define String constants even though String is not a primitive. Nobody would want to use Java if you had to write
String str = new String(new char[] {'C','a','k,'e'});
 
Thread starter Similar threads Forum Replies Date
truegenius Apps General Discussion 3
A Apps General Discussion 7
B Apps General Discussion 6
D Apps General Discussion 2
S Apps General Discussion 2
N Apps General Discussion 1
I Apps General Discussion 2
K Apps General Discussion 2
S Apps General Discussion 1
MrAlaweey98 Apps General Discussion 1
S Apps General Discussion 2
G Apps General Discussion 5
R Apps General Discussion 1
krahul44 Apps General Discussion 5
krahul44 Apps General Discussion 2
E Apps General Discussion 1
G Apps General Discussion 1
bsnowman17 Apps General Discussion 3

ASK THE COMMUNITY

TRENDING THREADS