The purpose of this project is to give students more exposur
Solution
package arraylist.program;
import java.util.*;
import java.util.Scanner;
public class ArrayListProgram
{
public static void main(String[] args) {
// enables keyboard input
Scanner input = new Scanner(System.in)
//this creates the Array!
ArrayList<String> animalArray = new ArrayList<String>();
// Adding items to arrayList
animalArray.add(\"Zebra\");
animalArray.add(\"Lion\");
animalArray.add(\"Fish\");
// Display the contents of the array list
System.out.println(\"The array contains the following animals: \ \" + animalArray);
// Checking if array list is empty
boolean check = animalArray.isEmpty();
System.out.println(\"\ Verifying if the animal list is empty: \" + check);
System.out.println(\"\ Please enter the name of the animal \" + \"you want to retrieve: \");
String[] animals = new String[3];
// add elements to the array
animals[0] = \"Zebra\";
animals[1] = \"Lion\";
animals[2] = \"Fish\";
// String[] animal;
// declare a string array with no initial size
String useranswer;
useranswer = input.next();
// 1st way: loop using index and size list
System.out.println(\"\ Retrieving animal information!\");
if (animals[0].equals(useranswer) )
{
String[] animals2 = {\"White & Black, Vetebrate, Non-Swim\"};
// declare string array and initialize with values in one step
int size = animals2.length;
System.out.println(\"The size of array is: \" + size);
for (int i = 0; i < size; i++)
{
System.out.println(\"\ Index[\" + i + \"] = \" + animals2[i]);
// iterate all the elements of the array
}
if( animals[1].equals(useranswer) )
{
String[] animals3 = {\"Orange,Vetebrate, Non-Swim\"};
// declare string array and initialize with values in one step
int size = animals3.length;
System.out.println(\"The size of array is: \" + size);
for (int i = 1; i < size; i++)
{
System.out.println(\"\ Index[\" + i + \"] = \" + animals3[i]);
// iterate all the elements of the array
}
}
}
}
}

