compare two lists java code example
Example 1: compare two strings java
String string1 = "using equals method";String string2 = "using equals method"; String string3 = "using EQUALS method";String string4 = new String("using equals method"); assertThat(string1.equals(string2)).isTrue();assertThat(string1.equals(string4)).isTrue(); assertThat(string1.equals(null)).isFalse();assertThat(string1.equals(string3)).isFalse();
Example 2: join two lists java
List<String> newList = Stream.concat(listOne.stream(), listTwo.stream())
.collect(Collectors.toList());
Example 3: java compare lists
List<String> firstList=Arrays.asList("Hello","World");
List<String> secondList=new ArrayList<>(firstList);
System.out.println(firstList.equals(secondList));
secondList.add("other element");
System.out.println(firstList.equals(secondList));