File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes toArray help plz Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "toArray help plz" Watch "toArray help plz" New topic

toArray help plz

Jamie Cotton

Joined: Nov 12, 2004
Posts: 16

hiya i have a method as the following

This should convert my MessageList ArrayList to an Array which is in a class called Inbox.

My question is that how do i print out all the items in the new array that i just created in a separate test program

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
So are you asking how to print out the contents of an array? If so, you should use a for loop to iterate through the array. Perhaps you should try this first to see what is print out.

However, I doubt you will get useful information since at the moment each element is only an Object. Do you know a more specific type for these elements? If so you should use that type when you call the toArray() method. For instance, if MessageList contains objects of class MyClass, you should do this:

Notice that you can still return Object[], but this ensures that the run-time type of each object is actually MyClass, rather than Object as before. Also, the cast that you had isn't necessary since toArray() already returns Object[].

The last tid-bit is to make sure your class (MyClass in this case) overrides toString() to return a String with useful information.

I sure hope this isn't too much information. I'm making several assuptions, so if I'm totally off track, perhaps you can post some more information. Specifically, it would be helpful to know what the elements of MessageList are.

Keep Coding!


p.s. Coding conventions typically state that variable names start with lower case, so MessageList should probably be messageList otherwise it looks like a class name to those of us that are used to the "standard" conventions.

Java API Documentation
The Java Tutorial
Jamie Cotton

Joined: Nov 12, 2004
Posts: 16

First thank you for the reply!

Second maybe for you tonderstand what i am trying to do i have upload my files link here(

Basically all I want is a method which converts my MessageList ArrayList the Inbox class to an Array and a little test program in Email Organiser that will display the contents of the new Array just created.

I agree. Here's the link:
subject: toArray help plz
It's not a secret anymore!