https://github.com/andresweitzel/java_11_exercises
Exercises with java 11. For example String class, Files class, Collection interface, Lambdas, Reflection Api, others.
https://github.com/andresweitzel/java_11_exercises
git java-11 java-exercises java-string-class
Last synced: 3 months ago
JSON representation
Exercises with java 11. For example String class, Files class, Collection interface, Lambdas, Reflection Api, others.
- Host: GitHub
- URL: https://github.com/andresweitzel/java_11_exercises
- Owner: andresWeitzel
- Created: 2023-12-21T19:46:48.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-04T22:53:43.000Z (almost 2 years ago)
- Last Synced: 2025-07-06T03:07:48.944Z (3 months ago)
- Topics: git, java-11, java-exercises, java-string-class
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Java_11_Exercises
Exercises with java 11. For example String class, Files class, Collection interface, Lambdas, Reflection Api, others.* [Oficial documentation](https://docs.oracle.com/en/java/javase/11/)
* [Recommended Guide](https://www.baeldung.com/java-11-new-features)
* [Online Java Compiler](https://www.jdoodle.com/online-java-compiler)
## Index 📜
See
### String Methods
* [Using the isBlank method.](#using-the-isblank-method-)
* [Using the lines method.](#using-the-lines-method-)
* [Using various methods](#using-various-methods)
## Project execution [🔝](#index-)
See
## String Methods
### Using the isBlank method [🔝](#index-)
#### Check if a string has empty spaces
See solution
* [isBlank method](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#isBlank())
#### Code
```java
public class TestClass {
public static void main(String args[]) {
/**
* public boolean isBlank()Returns true if the string is empty or contains only white space codepoints, otherwise false.
Returns:
true if the string is empty or contains only white space codepoints, otherwise false
Since:
11
See Also:
Character.isWhitespace(int)
*
*/
String firstString = "First String to test";System.out.println("First String : "+firstString.isBlank());
String secondString = " ";System.out.println("Second String : "+secondString.isBlank());
String thirdString = "";System.out.println("Third String : "+thirdString.isBlank());
}
}
```#### Console
```java
First String : false
Second String : true
Third String : true```
### Using the lines method [🔝](#index-)
#### Create a Java program to read a string and obtain the content as a stream of lines.
See solution
* [lines method exercises](https://howtodoinjava.com/java11/string-to-stream-of-lines/)
#### Code
```java
import java.util.stream.Stream;
public class Main
{
public static void main(String[] args)
{
try
{
String str = "A \n B \n C \n D";
Stream lines = str.lines();
lines.forEach(System.out::println);
}
catch (Error e)
{
e.printStackTrace();
}
}
}
```#### Console
```java
A
B
C
D```
### Using various methods [🔝](#index-)
#### Extract non-blank deleted lines from a multi-line string.
See solution
* [Using various methods](https://www.baeldung.com/java-11-new-features)
#### Code
```java
public class ExampleClass {
public static void main(String args[]) {
String multilineString = "Baeldung helps \n \n developers \n explore Java.";
List lines = multilineString.lines()
.filter(line -> !line.isBlank())
.map(String::strip)
.collect(Collectors.toList());
assertThat(lines).containsExactly("Baeldung helps", "developers", "explore Java.");
}
}
```#### Console
```java```