Vector of strings.....

Discussion in 'Java' started by boyracer87, Nov 5, 2006.

  1. boyracer87

    boyracer87 New Member

    Joined:
    Nov 5, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys

    I ahve a project due for collage soon and i hardly have it half done. im currently trying to make a vector of strings but when i try return the list, it only gives me the last one that i inserted...here is the piece of code:

    Code:
    String item = command.getSecondWord();
            
            if (item.equalsIgnoreCase("key1")){
    	      	System.out.println("You now have the first key\n");
    	        items.add("key1");
    	        System.out.print("Items in hand are: ");
    	        for(int i = 0; i < items.size() ;i++)
                        {
    		    System.out.print(items.elementAt(i));
                        System.out.print(" ");
    		    } 		
            }else if (item.equalsIgnoreCase("key2")){
                    System.out.println("You now have the second key\n");
    	 	items.add("key2");
    	 	System.out.print("Items in hand are: ");
                    for(int i = 0; i < items.size() ;i++)             
                        {
    		    System.out.print(items.elementAt(i));
                        System.out.print(" ");
                        }      
             }else{
                System.out.println("?????????????");
            
             }
    
    Could anyone tell me whats wrong..

    Cheers,
    ray
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice