aspose file tools*
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
Author

toArray help plz

Jamie Cotton
Greenhorn

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

thanx
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!

Layne

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
Greenhorn

Joined: Nov 12, 2004
Posts: 16
hiya

First thank you for the reply!

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

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.

Thanx
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: toArray help plz