ArrayList Learn programming Java

Lesson:

Dynamic Memory Management


Exercise:

ArrayList 8


Objetive:

Create a list of strings, using the class ArrayList which already exists in the DotNet Platform.

Once created, show all the items stored in the list.
Insert one new item in the second place of the list and then show again all the items checking if the insertion was correct.


Code:

package List;
import java.util.*;
public class Main
{
	static void main(String[] args)
	{
		ArrayList miLista = new ArrayList();
		miLista.add("Hola,");
		miLista.add("soy");
		miLista.add("yo");
		for each(String frase in miLista)
			System.out.println(frase);
		
        miLista.add(1, "Como estas?");
	}
}