
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
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