-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add java 8 question asked in interview
- Loading branch information
1 parent
c9cf97e
commit 0f90763
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...thTest/src/main/java/org/practice/dsa/java8/functional_programming/interview/Reverse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.practice.dsa.java8.functional_programming.interview; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class Reverse { | ||
// Given the list of strings, reverse the characters of String element of list not the order | ||
public static void main(String[] args) { | ||
List<String> list = Arrays.asList("Welcome", "to", "Java"); | ||
System.out.println(reverseString(list)); | ||
} | ||
|
||
public static List<String> reverseString(List<String> list) { | ||
return list.stream() | ||
.map(str -> new StringBuilder(str).reverse().toString()) | ||
.collect(Collectors.toList()); | ||
} | ||
} |