Is it possible to construct an array that contains Strings instead of ints?
Thanks.
Printable View
Is it possible to construct an array that contains Strings instead of ints?
Thanks.
That's what is taken as an arguement for the main method
public static void main(String[] args)
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.
Code: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]);
}
String array [];
or
String array [] = new String [];