aspose file tools
The moose likes Java in General and the fly likes Clarification on Array! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Clarification on Array!" Watch "Clarification on Array!" New topic
Author

Clarification on Array!

Prathamesh Gaddam
Ranch Hand

Joined: Feb 18, 2008
Posts: 58
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

Joined: Jul 08, 2003
Posts: 24057
    
  13

"[]" (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 ]

[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Clarification on Array!
 
Similar Threads
What is wrong with the following code?
Check the object array instance of string array
Memory question
Casting Array to Object
array casting