refactor streams ex

This commit is contained in:
Loredana Crusoveanu
2018-02-10 17:42:52 +02:00
parent 87a36777db
commit 50deec5b5c
2 changed files with 26 additions and 22 deletions
@@ -1,5 +1,7 @@
package com.baeldung.string;
import java.util.stream.IntStream;
public class Palindrome {
public boolean isPalindrome(String text) {
@@ -50,4 +52,10 @@ public class Palindrome {
return true;
}
public boolean isPalindromeUsingIntStream(String text) {
String temp = text.replaceAll("\\s+", "").toLowerCase();
return IntStream.range(0, temp.length() / 2)
.noneMatch(i -> temp.charAt(i) != temp.charAt(temp.length() - i - 1));
}
}