Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java ArrayList

ladyt
ladyt 


The following code creates a simple ArrayList: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Ex01 { public static void main(String[] args) throws IOException { BufferedReader userInput = new BufferedReader (new InputStreamReader(System.in)); ArrayList myArr = new ArrayList(); myArr.add("Zero"); myArr.add("One"); myArr.add("Two"); myArr.add("Three"); } } Starting with this provided code, add the following functionality: Add items to the ArrayList, one at a time, based on user typed input. The user will be prompted for the String to be stored in the ArrayList and then hit enter. The user will be able to continue to add items to the ArrayList until they just hit enter without typing anything. Once the user does this (hits enter without typing anything), the program will display all of the elements of the ArrayList, both the index and String values, in a table. It will do this via a single loop. Attachments
Tags Clarifications

Answers

Java ArrayList - Solution

dickersonka
dickersonka 



Attached is the solution to the Java ArrayList assignment including source and comments Attachments
Ex01.zip (4 K) Download
Preview

Preview
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Ex01 { public static void main(String[] args) throws IOException { BufferedReader userInput = new BufferedReader (new InputStreamReader(System.in)); ArrayList<String> myArr = new ArrayList<String>(); myArr.add("Zero"); myArr.add("One");

Screenshots
Screenshot
Purchase Answer

Java ArrayList - Answer

mariobeka
mariobeka 



Attached you will find the solution for the question that was asked, also I have provided the necessary comments to help you understand better the code. Attachments
JavaArrayList.zip (2 K) Download




Preview
the value is empty do{ System.out.print("Enter value: "); value = userInput.readLine(); // read the value myArr.add(value); // add the value in the array list } while(!value.equals("")); // end of the loop System.out.println("");

Screenshots
Purchase Answer