A. What's the difference between the following (except packages) and their usage:
1. Array 2. Arrays 3. [] (primitive or object type array)
B. Can we interchange the usage of methods among these Array declarations and in what all ways?
For Example: 1. Object [] myObjects; (assume with valid data) 2. Arrays.sort(myObjects); Note: Line 1 denoted general array type [] and line 2 uses method from Arrays collections framework.
Thank you for the needful, in advance.
Ernest Friedman-Hill
author and iconoclast
Marshal
"[]" (i.e., built-in arrays) are... well, they're arrays. An array of a given type can hold an ordered collection of items of that type.
Arrays (java.util.Arrays) is a collection of convenient utility method for working with arrays: sorting, searching, filling, etc. There's nothing essential in this class -- everything in this class you could write yourself. You can use these methods with any arrays, but in no sense can you "interchange Arrays and []" -- they're completely different things.
Array (java.lang.reflect.Array) is used in reflection, which means asking the JVM about the properties classes it contains. You can ask the JVM "What is the return type of the method foo() of the class Bar?" and if foo() returns some kind of array (i.e., some kind of "[]"), the JVM will use the Array class to pass you that information. This is a far more advanced topic. Again, it's not at all interchangeable with the other two -- it has a completely different purpose. [ April 14, 2008: Message edited by: Ernest Friedman-Hill ]