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 2 of 2

Thread: ArrayList Questions

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ArrayList Questions

    I am in an introduction class for Java, and I am having trouble with ArrayLists.

    I need to create a program that asks the user how many jobs they work, and then have the user be able to enter the income for each job. So the user will enter 3 jobs, and then the program will ask, "Enter the income for job 1:" And the user will enter a number, and it will store that number to be used and displayed later.

    I just don't understand how I can create an ArrayList with the length of jobs, and then have the user enter in data that will be saved to the ArrayList.


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: ArrayList Questions

    I just don't understand how I can create an ArrayList with the length of jobs, and then...
    You don't create an ArrayList with a particular length. Instead you create one and it will grow as data is added to it. In this respect instances of ArrayList are easier to work with than arrays (where the length is decided on once and for all when the array is created).

    JavaPF has an example of ArrayList usage at How to use an ArrayList and what is its advantage over array?

Similar Threads

  1. List of my Java3D Questions, and Proguard questions
    By Zachary1234 in forum Java SE APIs
    Replies: 0
    Last Post: November 16th, 2012, 08:40 PM
  2. How to use an ArrayList and what is its advantage over array?
    By JavaPF in forum Java SE API Tutorials
    Replies: 4
    Last Post: December 21st, 2011, 03:44 AM
  3. newby Questions - indexOf help with an ArrayList
    By Bially in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 20th, 2011, 06:05 PM
  4. Ordering ArrayList by 3 conditions as you add to ArrayList
    By aussiemcgr in forum Collections and Generics
    Replies: 4
    Last Post: July 13th, 2010, 02:08 PM
  5. [SOLVED] Extracting an How to ArrayList from an ArrayList and convert to int??
    By igniteflow in forum Collections and Generics
    Replies: 2
    Last Post: August 16th, 2009, 01:11 PM