Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Accessing String Array

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Accessing String Array

    Guys! I really need help. What does the line Console[] conList mean? How am I going to access the string values in class consolelist?
    class ConsoleInfo
    {
     
      private String conTitle;
      private double conPrice;
      private int conQty;
      private String conPic;
     
      private static String empPassword; 
     
        ConsoleInfo(String title, double price, int qty,String pic)
         {
            conTitle = title;
       	  conPrice = price;
       	  conQty = qty;
       	  conPic = pic;    	   
     
         }
       /*
     
       Finish the class off with the various set/get methods
       here
     
     */    
     public void setTitle(String a)
       {
          conTitle = a;
       }
       public String getTitle()
       {
          return conTitle;
       }
       public void setPrice(double a)
       {
          conPrice = a;
       }
       public double getPrice()
       {
          return conPrice;
       }
       public void setQty(int a)
       {
          conQty = a;
       }
       public int getQty()
       {
          return conQty;
       }
       public void setPic(String a)
       {
          conPic = a;
       }
       public String getPic()
       {
          return conPic;
       }
       public void setPass(String a)
       {
          empPassword = a;
       }
       public String getPass()
       {
          return empPassword;
       }
     
    }
     
    ///////////////////////////////
     
    class ConsoleList 
    {
     
      ConsoleInfo[] conList;
     
      public void createList()
      {
         conList = new ConsoleInfo[7];
     
    	    conList[0] = new ConsoleInfo("Xbox One",549.99,45,"xbox-one.jpg");
     
    	   conList[1] = new ConsoleInfo("Xbox 360",321.99,92,"xbox360.jpg");
    		conList[2] = new ConsoleInfo("PS4",678.99,72,"ps4.jpg");
     
    		conList[3] = new ConsoleInfo("PS3",447.99,11,"ps3.jpg");
    		conList[4] = new ConsoleInfo("Wii U",354.99,23,"wii-U.jpg");
          conList[5] = new ConsoleInfo("Sega Firecore",110.99,0,"sega-Firecore.jpg");
    	   conList[6] = new ConsoleInfo("Steam Machine",784.99,1,"steamMachine.jpg");        
      }
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Accessing String Array

    What does the line Console[] conList mean? How am I going to access the string values in class consolelist?
    Its an array. Suggested reading:
    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Accessing String Array

    I know it's an array. But what does the line conList = new ConsoleInfo[7] basically do? Is it storing the values in the constructor above? Sorry. I'm really confused. I'm stuck because of this

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Accessing String Array

    Did you read the link in post #2?

Similar Threads

  1. Accessing string list?
    By krulle in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 9th, 2014, 06:07 AM
  2. Convert List<Set<String>> to string array
    By shatlav in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 4th, 2013, 08:16 AM
  3. [SOLVED] Sorting an object array using string variables from a string array
    By Shadud in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 26th, 2012, 05:50 PM
  4. Accessing array of method
    By ncode in forum Java Theory & Questions
    Replies: 3
    Last Post: October 18th, 2012, 08:11 AM
  5. [SOLVED] Problem accessing specific data in an array and getting it to return properly
    By Universalsoldja in forum Collections and Generics
    Replies: 3
    Last Post: February 4th, 2010, 04:26 PM

Tags for this Thread