Results 1 to 4 of 4

Thread: Arrays

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    55

    Question Arrays

    Is it possible to construct an array that contains Strings instead of ints?

    Thanks.
    Beres

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    That's what is taken as an arguement for the main method
    public static void main(String[] args)

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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]);
       }

  4. #4
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332

    Wink or to put it much more clearly...

    String array [];

    or

    String array [] = new String [];
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width