File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes how to acess the elements in an array of array objects. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to acess the elements in an array of array objects." Watch "how to acess the elements in an array of array objects." New topic
Author

how to acess the elements in an array of array objects.

n haary
Greenhorn

Joined: Sep 20, 2011
Posts: 7
// the following is the code that creates and initialises an array.

public class ObjectArray
{
public static void main(String[] args)
{
Object[] o = new Object[]{new int[]{1,2,3}, new String[]{"one","two"}}; // this statement declares,creates and initialises an array of array objects
// can anyone explain me how can i get the elements from the integer array and string array which are elements of the Object array
}
}
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

You'll need to cast elements 0 and 1 to int[] and String[] respectively:
That may look intimidating, so don't be afraid to use a temporary variable instead:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
n haary
Greenhorn

Joined: Sep 20, 2011
Posts: 7
Rob Spoor wrote:You'll need to cast elements 0 and 1 to int[] and String[] respectively:
That may look intimidating, so don't be afraid to use a temporary variable instead:


thank you rob. thank you very much. its working.
you really gave a simple solution. thankyou once again.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

You're welcome.
 
Consider Paul's rocket mass heater.
 
subject: how to acess the elements in an array of array objects.
 
Similar Threads
GC-String array doubt
How many objects created?
Reference variable casting
How do I cast from Vector to String Array?
Arrays and strings