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 Convert a String[] array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convert a String[] array" Watch "Convert a String[] array" New topic

Convert a String[] array

Peter Simon

Joined: Oct 25, 2002
Posts: 14
A method returns a String[]array.
Could someone tell me how can i can get to the elements of this array, (since I don't know how many elements this array contains cannot write a for loop for this)
Can I convert or cast this array into some sort of a collection(Vector or ArrayList f.e.) so that i can use the methods .size() or .iterator()?

this is my code:
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

The .length member will give you the number of elements in the array. No conversions are necessary.
[ December 15, 2002: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Peter Simon

Joined: Oct 25, 2002
Posts: 14
and if wanted to convert because the elements are easyer to return from a collection,
how would I do this?
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
if you want to convert in to collection then you have populate the value of array to collection element.
Example create a ArrayList and populate each value of the array to ArrayList object and from ArrayList you can get collection.

Sharing is learning
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
You can simply use the Arrays.asList(Object[]) method.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: Convert a String[] array
It's not a secret anymore!