| 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 opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50691
|
|
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 ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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
|
 |
 |
|
|
subject: Convert a String[] array
|
|
|