I\'ve been trying to get the string initialize, but to no avail. I have tried all of the solutions I have come across and I am not sure whether it is because of my ineptness or
You can initialize the values of Strings
in two ways:
String abc = "I love basketball";
or
String abc = new String("I love basketball");
What you are seeing is a warning and not an error. If you insist on not putting a value into the String
, just do
String abc = null;
or
String abc = ""
In the latter case, your String is initialized to the characters between the quotations. Nothing, basically, but it is not null
.
To avoid potential NPE
problems, compare the String
s as follows:
"rock".equalsIgnoreCase(playerChoice);