Java 11 String Features

Posted By :Shivani Chaudhary |27th June 2019
 
 JDK11 New String strategies : 
 
There are some methods of String a part of Java 11 and helps developers to reduce committal to writing efforts. The strategies are listed below with Associate in an example.
 
1. strip() 
2. stripLeading() 
3. stripTrailing()
4. isBlank()
5. lines()
6. repeat(n)
 
1. The strip()  method used for remove the white space from start of string and end of String.
Example: String value = " hello ";
value.strip() output will be "hello"
 
2. stripLeading()  method used for remove the white area from the start of a string.
Example: String value = " hello ";
value.stripLeading() output will be "hello "
 
3. stripTrailing()  method used for remove the white area from the end of a string.
Example: String value = " hello ";
value.stripTrailing() output will be " hello"
 
 
Note : if we use both stripLeading() and stripTrailing() output will be same as strip() method
Example: String value = " hello ";
value.stripLeading().stripTrailing() output will be "hello"
 
 
 
4. isBlank() method returns true if the string is empty or contains solely white spaces; otherwise, it returns false.
Example: String value = "  ";
value.isBlank() output will be true
String value = "hello";
value.isBlank() output will be false
 
 
5. lines() method used the stream of strings that square measure divided by line terminators. The lines within the stream square measure within the order during which they occur within the string. This technique is a lot of performant compared to the strategies we have a tendency to square measure mistreatment presently.
Example: String value = "Hello how are you \n I'm fine \n";
value.lines().collect(Collectors.toList());
output will be [Hello how are you , I'm fine ]
 
 
 
6. repeat(n) method used for the concatenated string, and also the variety of times it'll concatenate is dependant upon the count that we have to provide in method argument.
Example: String value = "Hello ";
value.repeat(3) output will be "HelloHelloHello"
 
 

About Author

Shivani Chaudhary

Shivani is a quick learner, self problem-solving, quickly grasp new things and hard-working Java Developer. She has good knowledge about Java, Spring MVC, Spring boot, Spring Data JPA, Hibernate, REST Web Services. Her hobbies are travelling and learning

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us