An open API service indexing awesome lists of open source software.

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.

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

```