- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
Advertisements