This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Executor executor = new CompletableFuture<>().defaultExecutor(); | |
CompletableFuture nameFuture = CompletableFuture.supplyAsync(() -> "Deepak", executor); | |
// Should be avoided, only for demonstration purpose | |
System.out.println(nameFuture.join()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String name = "Deepak"; | |
System.out.println(name.repeat(4)); // DeepakDeepakDeepakDeepak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String name = "Deepak\nKanika"; | |
List<String> names = names.lines().collect(Collectors.toList()); | |
System.out.println(names); // [Deepak, Kanika] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.pcollections</groupId> | |
<artifactId>pcollections</artifactId> | |
<version>3.1.0</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CheckedFunction0<Integer> checkedFunction1 = () -> 2; | |
Future<Integer> of = Future.of(checkedFunction1); | |
System.out.println(of.get()); |