+ 2
how to declare a string variable.I just get confused
either string args or string[ ] args
4 Answers
+ 5
In Java you must declare String with uppercase "S".
for example:
String strName = "Iman";
+ 4
in Java you can define string in two way
1) String variable_name = "";. (this is implicit way)
2) String variable_name = new String(): (this is explicit way)
+ 3
String variable_name;
or
String variable_name=new String ();
+ 1
basic first, to declare a variable, the syntax must be :
<class / datatype> <var name>;
or
<class / datatype> <var name> = <some value>;
well, to declare String, you can do things like :
1. String variable_name;
2. String variable_name = "some variable";
3. String variable = "what";
String variable_name = variable;
4. String variable_name = new String();
(String is a class, not a primitive datatype)
for String[ ], any class that declared ends with [ ] is an array, so you can declare it like this :
1. String[] variable_name;
2. String[] variable_name = new String[5]; //5 space of array of string
3. String[] variable_name = {"name0","var1","2array"};
in case of String[] args as parameter in java main method, it actually have the same function like when (if you use os windows) you press windows button + r and you type chrome "www.sololearn.com" and when you run it, browser chrome will open www.sololearn.com