So I\'m trying to find all the uppercase letters in a string put in by the user but I keep getting this runtime error:
Exception in thread \"main\" java.lan
With Java 8 you can also use lambdas. Convert the String
into a IntStream
, use a filter to get the uppercase characters only and create a new String
by appending the filtered characters to a StringBuilder
:
Scanner in = new Scanner(System.in);
System.out.print("Please give a string: ");
//Uppercase
String isUp = in.next()
.chars()
.filter(Character::isUpperCase)
.collect(StringBuilder::new, // supplier
StringBuilder::appendCodePoint, // accumulator
StringBuilder::append) // combiner
.toString();
System.out.println("The uppercase characters are " + isUp);
//Uppercase
Inspired by: