-
-
Save uncoded-ro/6e781c89d323dc76d6f75a739cbc6e0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ro.virtualcampus.list; | |
import java.util.ArrayList; | |
public class AppArrayList { | |
public static void main(String[] args) { | |
int tablou[] = { 5, 1, 3, 4, 6, 1, 7 }; | |
ArrayList<Integer> lista = new ArrayList<Integer>(); | |
for (int i = 0; i < tablou.length; i++) { | |
lista.add(Integer.valueOf(tablou[i])); | |
} | |
lista.add(1, 2); | |
System.out.println(lista); | |
System.out.printf("numarul de elemente din lista %s este %d %n", lista, lista.size()); | |
System.out.printf("indexul primei aparitii a elementului %d in lista %s este %d %n", | |
1, lista, lista.indexOf(1)); | |
System.out.printf("indexul ultimei aparitii a elementului %d in lista %s este %d %n", | |
1, lista, lista.lastIndexOf(1)); | |
lista.add(Integer.valueOf(8)); | |
lista.set(2, Integer.valueOf(2)); | |
System.out.println(lista); | |
System.out.printf("elementul de pe ultima pozitie (%d) in lista %s este %d %n", | |
lista.size() - 1, lista, lista.get(lista.size() - 1)); | |
lista.remove(lista.size() - 1); | |
System.out.printf("parcurgere elemente lista folosind for %n"); | |
for (int i = 0; i < lista.size(); i++) { | |
Integer element = lista.get(i); | |
int intVal = element.intValue(); | |
System.out.printf("%d, ", intVal); | |
} | |
System.out.printf("%n"); | |
System.out.printf("parcurgere elemente lista folosind for-each %n"); | |
for (Integer element : lista) { | |
int intVal = element.intValue(); | |
System.out.printf("%d, ", intVal); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment