- 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
Map to get substring and convert to int in Java
Let’s say the following is our stream:
Stream.of("u2", "h9", "s8", "l3")
Now, map to get the substring:
.map(s -> s.substring(1))
Convert to int and find the minimum:
.mapToInt(Integer::parseInt) .min()
The following is an example to Map and get substring and convert to int:
Example
import java.util.stream.Stream; public class Demo { public static void main(String[] args) throws Exception { Stream.of("u2", "h9", "s8", "l3") .map(s -> s.substring(1)) .mapToInt(Integer::parseInt) .min() .ifPresent(System.out::println); } }
Output
2
Advertisements
To Continue Learning Please Login
Login with Google