Click to See Complete Forum and Search --> : Arrays
Beres
Sep 9th, 2002, 03:47 PM
Is it possible to construct an array that contains Strings instead of ints?
Thanks.
Dillinger4
Sep 10th, 2002, 12:15 AM
That's what is taken as an arguement for the main method
public static void main(String[] args)
Dillinger4
Sep 10th, 2002, 01:02 AM
Here is a quick example which creates a String array and populates it with a string that has been parsed. Also notice how the string array is being passed as an arguement to the openVault(String[] vault) method which has a string array defined as a parameter.
import java.util.*;
class FortKnox{
public static void main(String[] args){
String s = "bronze silver gold ";
StringTokenizer st = new StringTokenizer(s);
String[] vault = new String[3];
int index = -1;
while(st.hasMoreTokens()){
String token = st.nextToken();
vault[++index] = token;
}
openVault(vault);
}
public static void openVault(String[] vault){
System.out.print("The contents of the vault are");
System.out.println();
for(int i = 0; i < vault.length; i++){
System.out.println(vault[i]);
}
CaptainPinko
Sep 10th, 2002, 08:04 PM
String array [];
or
String array [] = new String [];
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.