-1
How to compare two Lists and add different record in a third list??
Ex: List 1(1,2,3,4) List 2(1,2,3) List 3.add(4);
-1
How to compare two Lists and add different record in a third list??
Ex: List 1(1,2,3,4) List 2(1,2,3) List 3.add(4);
3
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Teste {
public static void main(String[] args) {
List<Integer> lista1 = Arrays.asList(1,2,3,4);
List<Integer> lista2 = Arrays.asList(1,2,3);
//clona lista 1
List<Integer> lista3 = new ArrayList<Integer>(lista1);
// remove todos os intems da lista 2
lista3.removeAll(lista2);
System.out.println(lista3);
}
}
Vlw For the help of Marciano.
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.
It depends on the result you want. Which is?
– Filipe L. Constante
It has to be list or it can be set (
Set
)? In the set the elements do not repeat, in the list yes.– Piovezan