It's not a secret anymore!*
The moose likes Beginning Java and the fly likes String values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String values" Watch "String values" New topic
Author

String values

Chris Davies
Ranch Hand

Joined: Feb 26, 2003
Posts: 110
hi

are the following 3 valid uses of string ?

String s ="i'm a string";
String s = (String) 'i'm a string';
String s = null;

cheers

chris


One day all greenhorns will run free ...
Rikard Qvarforth
Ranch Hand

Joined: Jul 10, 2001
Posts: 107
String s = "i'm a string"; -- valid
String s = (String) 'i'm a string'; -- not valid , invalid char, no ''
String s = null; -- valid, can always set an object to null


cheers Rille
Chris Davies
Ranch Hand

Joined: Feb 26, 2003
Posts: 110
String s = "i'm a string"; -- valid
String s = (String) 'i'm a string'; -- not valid , invalid char, no ''
String s = null; -- valid, can always set an object to null


so you can't expicitly cast an object to a value ? is it because string is not a wrapper class ?

cheers

chris
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Chris,

Did you try to compile your code snippet? A few compiler errors are worth a thousand words of explanation in a forum; OK, maybe only a hundred.

In any case, your example 2 uses single quotes.

Let me ask you (pull out your compiler please) is this one valid?

String s = (String) "i'm a string";
Chris Davies
Ranch Hand

Joined: Feb 26, 2003
Posts: 110
yes i see it. its what i originally thought but number 2 threw me a bit in terms of casting.

cheers

chris
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: String values
 
Similar Threads
100 times "hello world" without loop or recursive
How to convert from binary to int?
Problem with String
GC
question 1