What does this new code String [] and String.value () mean?
It:
String[] strArray = new String[]{
// ...
};
... creates an array String
and initializes it with the entries in the part {...}
. In your case, there is only one entry.
Why String is instantiated as an object, and what
valueOf(1);
As the documentation will tell you , String.valueOf(int)
creates a string representation of the integer value you are passing in.
So, what does this code creates an array String
with one record "1"
. It is unclear why the author would write String.valueOf(1)
and not just "1"
.
source to share
String.valueOf(...)
- a method that parses an object or primitive and creates a string representation of that object. For example, integer 1 will be converted to the string "1" (as in your example).
String[] strArray = new String[]{
String.valueOf(1)
};
means we create an array of strings (basically an array containing multiple strings) and add a string containing "1" to it (see my explanation above).
source to share
The code snippet in the question looks wrong. and I hope this should be next.
String[] s= new String[]{
String.valueOf(1)
};
String.valueOf (1) "Returns the string representation of the int argument."
values โโreturned from "String.valueOf (1)" is assigned to the string array object. The value "1" will be stored in the 0th index.
I am a bit confused as to why the question is marked with a voice. If the question is wrong, we can edit and change, right?
source to share