With the introduction of Java 8, Java has bought in lot of features for us.

Features of Java 8

Here is a brief summary of the enhancements included with the Java 8 release:

  • Lambda Expression and Virtual Extension Methods
    Highlighting feature of Java SE 8 is the implementation of Lambda expressions and supporting features to the Java programming language and platform.
  • Date and Time API
    This new API will allow developers to handle date and time in a more natural, cleaner and easier to understand way.
  • Nashhorn JavaScript Engine
    A new lightweight, high performance implementation of JavaScript engine is integrated to JDk and is available to Java applications via existing APIs.
  • Improved Security
    Replacing the existing hand-maintained list of caller sensitive methods with a mechanism that accurately identifies such methods and allows their callers to be discovered reliably.

To check if a string is a Palindrome in java 8

import java.util.Scanner;
import java.util.function.Predicate;

public class Palindrome {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a String");
        String palindrome = in.next();
        Predicate<Character> palin = (a) -> {
            if(palindrome.indexOf(a)+1==palindrome.length()-palindrome.lastIndexOf(a)){
                return  true;
            }
            return  false;
        };
        char[] allChars = palindrome.substring(0,palindrome.length()/2).toCharArray();
        boolean flag=true;
        for(char c:allChars){
            flag=palin.test(c);
            if(!flag){
                break;
            }
        }
        System.out.println(flag);

    }
}