Java 11 Features
1) Running Java File with single command
One major change is that you don’t need to compile the java source file with javac tool first. You can directly run the file with java command and it implicitly compiles.
2) Java String Methods
isBlank() – This instance method returns a boolean value. Empty Strings and Strings with only white spaces are treated as blank.
import java.util.*;
import java.util.*; public class Main { public static void main(String[] args) throws Exception { // Your code here! System.out.println(" ".isBlank()); //true String s = "Anupam"; System.out.println(s.isBlank()); //false String s1 = ""; System.out.println(s1.isBlank()); //true } }
}
lines() - This method returns a stream of strings, which is a collection of all substrings split by lines.
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) throws Exception {
String str = "JD\nJD\nJD";
System.out.println(str);
System.out.println(str.lines().collect(Collectors.toList()));
}
}
The output of the above code is:
repeat(int)
The repeat method simply repeats the string that many numbers of times as mentioned in the method in the form of an int.
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
String str = "=".repeat(2);
System.out.println(str); //prints ==
}
}
Comments
Post a Comment