Check if a string ends With Line Separator - Java java.lang

Java examples for java.lang:String End

Description

Check if a string ends With Line Separator

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String txt = "java2s.com";
        System.out.println(endsWithLineSeparator(txt));
    }/*w  w  w  .j  a  va 2 s.  co m*/

    private static final String separator = "\n";

    public static boolean endsWithLineSeparator(String txt) {
        return txt.endsWith(separator);
    }

    public static boolean endsWithLineSeparator(CharSequence txt) {
        return txt.length() != 0
                && txt.charAt(txt.length() - 1) == separator.charAt(0);
    }
}

Related Tutorials