+ 1
public class Program { public static void main(String[] args) { String[ ] myNames = newstring[5]; mystring[]={ "A", "B", "C", "D"}; System.out.println(myNames[2]); } }
In the explanation it is said that we can initialize the capacity of array using keyword " new".when I applied the same logic for string it was showin error. Please help me out with this code. Tanks in advance.
6 Respuestas
+ 2
String[ ] myNames = { "A", "B", "C", "D"};
System.out.println(myNames[2]);
You don't need the rest, is that what you are asking?
0
My Question is whether we can do declaration and assignment separately?
0
I want to print only C not ol the chracters..
0
yes u can do that separately,bt remember that size mst be defined at the time of declaration if u r doing so
0
you have declared the array name as myNames , initialized using mystring and again printing using myNames.
That is why the error message is showing.
Do it correctly
- 4
i don't think you can with Strings , since String has slightly different behavior than regular arrays