Find Duplicates In Arraylist Java Code Example

Snippet 1 // Uses a set, which does not allow duplicates for (String name : names) { if (set.add(name) == false) { // your duplicate element } } Snippet 2 package dto; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; /** * Java Program to find duplicate elements in an array. There are… Continue reading Find Duplicates In Arraylist Java Code Example

Filter Vs Find Java Code Example

Snippet 1 return dataSource.getParkingLots() .stream() .filter(parkingLot -> Objects.equals(parkingLot.getId(), id)) .findFirst() .orElse(null); Copyright © Code Fetcher 2020    

Published

Filter Stream With List Java Code Example

Snippet 1 items.stream() .filter(s->s.contains(“B”)) .forEach(System.out::println); Snippet 2 List result = lines.stream() .filter(line -> “theLineIWant”.equals(line)) .collect(Collectors.toList()); Copyright © Code Fetcher 2020    

Published

Different Type Of Set Methods Java Code Example

Snippet 1 import java.util.*; public class SetDemo { public static void main(String args[]) { int count[] = {34, 22,10,60,30,22}; Set set = new HashSet(); try { for(int i = 0; i < 5; i++) { set.add(count[i]); } System.out.println(set); TreeSet sortedSet = new TreeSet(set); System.out.println("The sorted list is:"); System.out.println(sortedSet); System.out.println("The First element of the set is:… Continue reading Different Type Of Set Methods Java Code Example

Date To Iostring Code Example

Snippet 1 Format formatter = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); String s = formatter.format(date); Copyright © Code Fetcher 2020    

Published

Creating Java Main Method Code Example

Snippet 1 public class Test { public static void main(String[] args){ System.out.println(“Hello World”); } } Snippet 2 public class Test { static void main(String[] args){ System.out.println(“Hello World”); } } Copyright © Code Fetcher 2020    

Published

Create Variable In Java Code Example

Snippet 1 int // int is a variable the stores numbers string // a variable for storing text Copyright © Code Fetcher 2020    

Published