-
-
Save uncoded-ro/b467f97bdfdaacf351cb13897eb333df 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; | |
import java.util.Collections; | |
import java.util.LinkedList; | |
import java.util.List; | |
public class AppLinkedList { | |
public static void main(String args[]) { | |
int tablou[] = { 5, 1, 3, 4, 6, 1, 7 }; | |
ArrayList<Integer> lista1 = new ArrayList<Integer>(); | |
for (int i = 0; i < tablou.length; i++) { | |
lista1.add(Integer.valueOf(tablou[i])); | |
} | |
System.out.println(lista1); | |
LinkedList<Integer> lista2 = new LinkedList<Integer>(lista1); | |
System.out.println(lista2); | |
lista2.addFirst(6); | |
System.out.printf("elementul de pe prima pozitie din lista %s este %d %n", | |
lista2, lista2.getFirst()); | |
lista2.removeFirst(); | |
lista2.addLast(5); | |
System.out.printf("elementul de pe ultima pozitie din lista %s este %d %n", | |
lista2, lista2.getLast()); | |
lista2.removeLast(); | |
List<Integer> lista3 = lista2.subList(3, 7); | |
System.out.printf("sublista %s din lista %s %n", lista3, lista2); | |
Collections.sort(lista3); | |
System.out.printf("sublista ordonata este %s %n", lista3); | |
Collections.reverse(lista3); | |
System.out.printf("sublista ordonata invers este %s %n", lista3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment