Skip to content

Instantly share code, notes, and snippets.

View deepakmehra10's full-sized avatar
🎯
Focusing

Deepak Mehra deepakmehra10

🎯
Focusing
View GitHub Profile
CompletableFuture nameFuture = CompletableFuture.supplyAsync(() -> "Deepak");
CompletableFuture nameFutureCopy = nameFuture.copy();
CompletableFuture withSurname = nameFuture.thenApply(name -> "Deepak Mehra");
// Should be avoided, only for demonstration purpose
System.out.println(withSurname.join());
// Change in original instance should affect it's copy instance.
System.out.println(nameFutureCopy.join());
Executor executor = new CompletableFuture<>().defaultExecutor();
CompletableFuture nameFuture = CompletableFuture.supplyAsync(() -> "Deepak", executor);
// Should be avoided, only for demonstration purpose
System.out.println(nameFuture.join());
String name = "Deepak";
System.out.println(name.repeat(4)); // DeepakDeepakDeepakDeepak
String name = " Deepak Mehra ";
System.out.println(name.strip()); // Deepak Mehra(Whitespaces removed already)
String name = " Deepak Mehra ";
System.out.println(name.stripLeading()); // Removes only leading whitespaces
String name = " Deepak Mehra ";
System.out.println(name.stripTrailing()); // Removes only trailing whitespaces
String name = "Deepak\nKanika";
List<String> names = names.lines().collect(Collectors.toList());
System.out.println(names); // [Deepak, Kanika]
String name = "";
System.out.println(name.isEmpty()); // true
String name1 = " ";
System.out.println(name1.isEmpty()); // false
String name2 = " ";
System.out.println(name2.isBlank()); // true
String name3 = "";
List students = Arrays.asList("Deepak", "Bhawna", "Charmy", "Vinisha");
// Create a Pvector collection.
PVector pVector1 = TreePVector.from(students);
PVector rahul = pVector1.plus("Rahul");
System.out.println(pVector1); // Output - [Deepak, Bhawna, Charmy, Vinisha]
System.out.println(rahul); // Output - [Deepak, Bhawna, Charmy, Vinisha, Rahul]
List students = Arrays.asList("Deepak", "Bhawna", "Charmy", "Vinisha");
// Create a Pvector collection.
PVector pVector1 = TreePVector.from(students);
pVector1.plus("Rahul");
System.out.println(pVector1);
// Output - [Deepak, Bhawna, Charmy, Vinisha]
<dependency>
<groupId>org.pcollections</groupId>
<artifactId>pcollections</artifactId>
<version>3.1.0</version>
</dependency>
CheckedFunction0<Integer> checkedFunction1 = () -> 2;
Future<Integer> of = Future.of(checkedFunction1);
System.out.println(of.get());