This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convert a String[] array" Watch "Convert a String[] array" New topic
Author

Convert a String[] array

Peter Simon
Greenhorn

Joined: Oct 25, 2002
Posts: 14
Hi,
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()?
thanks,
Peter

this is my code:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

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

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peter Simon
Greenhorn

Joined: Oct 25, 2002
Posts: 14
thanks,
and if wanted to convert because the elements are easyer to return from a collection,
how would I do this?
Peter
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.
-arun


Sharing is learning
Ilja Preuss
author
Sheriff

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: http://aspose.com/file-tools
 
subject: Convert a String[] array
 
Similar Threads
Array
Verifying element types of a Vector
Vector array
Class Cast Exception - Please help
Collection