Discussion on Arrays and Lists

Discussion on Arrays and Lists

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

// Main Entry point for the program

    public static void main(String[] args) {

        //initialize Array List, scanner and

        ArrayList<String> student = new ArrayList<>();  

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

        Scanner scanner = new Scanner(System.in);       

        int studentNumber;

        //Prompt student to enter te number of students

        System.out.println(“Enter the Number of students”);

        studentNumber = scanner.nextInt();

        //add values to list

        addValuesToList(student, studentNumber, scanner);

        System.out.println(“\n”);

        //retreive valued from the list

        retrieveFromList(student);  

    }

//Funtion for retrieving values from list

    public static void retrieveFromList(List student)

    {      //Initialize the size variable to the size of the student List

        int size = student.size();

            for(int i=0;i<size;i++)

            {

                System.out.println(student.get(i));// Print each student entry

            }

    }

//Function for adding values to the list

    public static void addValuesToList(List students, int number, Scanner scanner)

    {      //Loop through the student list

        for(int i=0;i<number;i++){

            System.out.println(“Enter the Student Name”);

            students.add(scanner.next());//Add new student item to Student list

        }

    }

The program is designed to iteratively capture the name of students. The program makes use of an ArrayList data structure that implements the List interface to allow the user to enter an arbitrary number of students into the program. Through using a loop, the program allows a user to perform the same operation a given number of time (Langsam, Augenstein & Tenenbaum, 2003). In this specific instance, the loop allows the entry of the student name the specified number of times. The program allows the user to specify the number of students, after which a counter is set and the program performs the operations necessary to capture the specified number of users. This is a good coding practice since it eliminates the possibility of errors in code.

The second best coding practice seen in this code lies in the use of an ArrayList. This data structure allows for the storage and manipulation of data collections without prior need for establishing the length. If an array had been used in a similar instance, then the array length would have had to be predetermined (Riley, 2003). In this instance, the use of an array to store student names would have necessitated the declaration of the number of elements the array was to hold. This would have been fine for say a class with a known number of student, but an inherent limitation emerges. The limitation arises from the fact that the code would not be used for any other class, except if it had the same number of students (Sierra & Bates, 2005). The code might be applied to cases where the number of students was less than that of the length of the array which case it would waste memory. Evidently, the use of ArrayLists presents a good coding practice.

The use of these two coding practices are also in line with how computers operate. Computers are exceptionally good at handling large sets of data. Similarly, they are very good at performing repeated operations on subsets of the data over and over again. In this regard, loops prove beneficial as they provide the means through which the computer can iteratively handle each subset of the data until the operation is done. Similarly, ArrayLists present similar benefits. The advantage an ArrayList offers is ability to dynamically add or remove elements. As is typical in real life situations, we may be unaware of how many values a we require to perform a given operation on. The ArrayList offers this. When working with ArrayLists one needs not specify the length of the structure. The combination of a structure which can hold as many elements as the memory allows provided by an ArrayList, coupled with the ability to perform a related set of operations on a subset of the data, provided by the loop construct is exactly what makes the computer a good tool for performing computation on large sets of data.

References

Langsam, Y., Augenstein, M., & Tenenbaum, A. (2003). Data structures using Java. Upper Saddle River, N.J.: Pearson Prentice Hall.

Riley, D. (2003). The object of data abstraction and structures using Java. Boston: Addison Wesley.

Sierra, K., & Bates, B. (2005). Head first Java. Sebastopol, CA: O’Reilly

Place your order
(550 words)

Approximate price: $22

Homework help cost calculator

600 words
We'll send you the complete homework by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 customer support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • 4 hour deadline
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 300 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more