

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to approach String as int stream in Java
Let’s say we have the following string:
String str = "YuBM787Nm";
Now to display it as IntStream, use filter() and map() as shown below:
int res = str.chars() .filter(Character::isDigit) .map(ch → Character.valueOf((char) ch)).sum();
The following is an example to display string as IntStream:
Example
public class Demo { public static void main(String[] args) { String str = "YuBM787Nm"; int res = str.chars() .filter(Character::isDigit) .map(ch -> Character.valueOf((char) ch)).sum(); System.out.println("String as IntStream = "+res); } }
Output
String as IntStream = 166
- Related Questions & Answers
- How to convert int to String in java?
- Convert String to Java int
- Convert int to String in Java
- How to filter String stream and map to lower case in Java? Perform sort as well.
- How to convert string Stream to join them in Java?
- How to convert a String into int in Java?
- How to convert a Java String to an Int?
- How to convert a String to an int in Java
- Concatenate string to an int value in Java
- Java Program to convert a String to int
- Java Program to convert int to binary string
- Java Program to convert int to Octal String
- Java Program to convert mathematical string to int
- How to convert/read an input stream into a string in java?
- Java Program to sort String Stream with reversed Comparator
Advertisements