Hi all, I have a easy question: in the sample main: public static void main(String args[]) ....... how can I know how many Strings into args there are ? exist args.length() or somethong like it? thanks
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
args.length (without the parens) is a property of the args String array, not to be confused with args[0].length() which is a method of the String class to find the length of the first string in the args String array. [ January 10, 2002: Message edited by: Marilyn deQueiroz ]
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
marco tognoni
Greenhorn
Joined: Jan 07, 2002
Posts: 17
posted
0
thanks, but in the documentation of JDK 1.3 I didn't find any explanation of string array property. Where can I find some document to see string array properties ? thanks in advance
Fei Ng
Ranch Hand
Joined: Aug 26, 2000
Posts: 1241
posted
0
Originally posted by marco tognoni: thanks, but in the documentation of JDK 1.3 I didn't find any explanation of string array property. Where can I find some document to see string array properties ? thanks in advance
like Marilyn deQueiroz has said.. array has my_array.length, that array properties. String hs my_string.length(), that String properties.
String array properites? They are two different things. look at the DOC of 1.3 again. You will find them where they should be. look at array and string.
marco tognoni
Greenhorn
Joined: Jan 07, 2002
Posts: 17
posted
0
sorry, which package the array class stay in ? I found no property for array, but maybe i looked for in the wrong package...... thanks
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
posted
0
It's in java.lang package. It's already availabe to you...you do not have to import it.
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
marco tognoni
Greenhorn
Joined: Jan 07, 2002
Posts: 17
posted
0
again sorry, I didn't understand. In the java.lang package there is the class String, not Array class. I understood that Array class had property "length". I don't know where to find this property.
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
There are two different things here, there is the array that is built into the java language, and the Array class that is found in java.lang.reflect.Array. The rules for the array type that is built in can be found here. there is not a class in the API for them any more than there is a class for integer or character. However they are still considered a class that has a length field (not a length() method). Every array implements the interfaces Cloneable and java.io.Serializable because the Lava Language Specification says that they have to, so that is built into the language. That make arrays a very special sort of thing in Java. Yeah - yeah - I know, it also sort of makes Java less purely object oriented than some languages. But that was a sacrifice that was made in the interest of efficiency. The Array wrapper class has a bunch of static methods to help manipulate arrays.
"JavaRanch, where the deer and the Certified play" - David O'Meara
marco tognoni
Greenhorn
Joined: Jan 07, 2002
Posts: 17
posted
0
It is ok now!! Thanks for your exhaustive explanation. It was not easy .... but ok.
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
Originally posted by marco tognoni: I didn't understand. In the java.lang package there is the class String, not Array class. I understood that Array class had property "length".
I don't know where to find this property.
In Java there are different types of variables. There are primitives, like int, char, and double; there are objects, like String, Character, and MyObject; and there are Arrays which are a special kind of object in Java that can hold numerous primitive variables or object references. When you create an array, it "knows" the kind of data that it can contain and the number of items that it can hold.
int[] totals = new int[200] for instance the kind of data that it can contain: int the number of items that it can hold: 200
String[] args This array is created when main is called. the kind of data that it can contain: String the number of items that it can hold: determined upon creation of the array. When main() is called, the number of Strings on the command line is counted and a String array of that length is created.
You can find the length of any array by using arrayName.length
"array" is a type, like "primitive". See the reference Cindy gave above ("The rules for the array type that is built in can be found here.") [ January 11, 2002: Message edited by: Marilyn deQueiroz ]