import java.util.ArrayList;
public class FishTank
{
public static void main (String[] args)
{
ArrayList < String > myFish = new ArrayList < String > ();
myFish.add ("Fishy");
myFish.add ("Blinky");
myFish.add ("Nemo");
myFish.add ("Sir Blubs a lot");
System.out.println (myFish);
//Adding a fish
myFish.add (2, "Cutter");
System.out.println (myFish);
//Isolate a fish and prints it
System.out.println (myFish.get (3));
//Fish in position dies! :(
myFish.remove (1);
System.out.println (myFish);
//Gives index position of Nemo... FINDING NEMO!
System.out.println (myFish.indexOf ("Nemo"));
//Nemo actually dies
myFish.remove (myFish.indexOf ("Nemo"));
//How many fish there are
System.out.println (myFish.size ());
for (int i = 0; i < myFish.size (); i++)
{
System.out.println (myFish.get (i));
}
//same as the for loop above
for (String fish : myFish)
{
System.out.println (fish);
}
}
}
public class FishTank
{
public static void main (String[] args)
{
ArrayList < String > myFish = new ArrayList < String > ();
myFish.add ("Fishy");
myFish.add ("Blinky");
myFish.add ("Nemo");
myFish.add ("Sir Blubs a lot");
System.out.println (myFish);
//Adding a fish
myFish.add (2, "Cutter");
System.out.println (myFish);
//Isolate a fish and prints it
System.out.println (myFish.get (3));
//Fish in position dies! :(
myFish.remove (1);
System.out.println (myFish);
//Gives index position of Nemo... FINDING NEMO!
System.out.println (myFish.indexOf ("Nemo"));
//Nemo actually dies
myFish.remove (myFish.indexOf ("Nemo"));
//How many fish there are
System.out.println (myFish.size ());
for (int i = 0; i < myFish.size (); i++)
{
System.out.println (myFish.get (i));
}
//same as the for loop above
for (String fish : myFish)
{
System.out.println (fish);
}
}
}
(0) Comments
Post a Comment