ArrayList Learn programming Java

Lesson:

Dynamic Memory Management


Exercise:

ArrayList


Objetive:

Create a string list using the ArrayList class that already exists in the .NET platform.

Once created, display all the items stored in the list. Insert a new item in the second place of the list, and then display all the items again to check if the insertion was done correctly.


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?");
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.