Ejemplo 1: cómo comparar dos listas de matrices son iguales en java
public class ArrayListExample
{
public static void main(String[] args)
{
ArrayList<String> listOne = new ArrayList<>(Arrays.asList("a", "b", "c", "d", "f"));
ArrayList<String> listTwo = new ArrayList<>(Arrays.asList("a", "b", "c", "d", "e"));
Collections.sort(listOne);
Collections.sort(listTwo);
//Compare unequal lists example
boolean isEqual = listOne.equals(listTwo); //false
System.out.println(isEqual);
//Compare equals lists example
ArrayList<String> listThree = new ArrayList<>(Arrays.asList("a", "b", "c", "d", "f"));
isEqual = listOne.equals(listThree); //true
System.out.println(isEqual);
}
}
Ejemplo 2: comparar con arraylist java
import java.util.*;
public class ComapreArraylistExample1
{
public static void main(String args[])
{
//first array list
ArrayList<String> firstList=new ArrayList<String>();
//adds elements to the arraylist
firstList.add("Apple");
firstList.add("Pears");
firstList.add("Guava");
firstList.add("Mango");
//second array list
List<String> secondList=new ArrayList<String>();
//adds elements to the arraylist
secondList.add("Apple");
secondList.add("Pears");
secondList.add("Guava");
secondList.add("Mango");
//comparing both lists
boolean boolval = firstList.equals(secondList);
//returns true because lists are equal
}
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)