Can anybody elaborate the difference between “Char” and “String” at Java

Total Post:19

Points:133
Java 
 1412  View(s)
Ratings:
Rate this:

What is the difference between the JDK6 java.util.regex.Pattern's "Boundary matchers" '\z' and '\Z'?

Background: I was trying to read a UTF-8 encoded file's contents into a String.

  1. Post:24

    Points:168
    Re: Can anybody elaborate the difference between '\Z' and '\z' in java.util.regex.Pattern?

    The difference is anchor \Z matches the empty string just before the newline, while \z matches empty string after the newline.

    A very simple example to understand this is:


    System.out.println("abc\n".matches("abc\\Z\\n"));   // true
    
    System.out.println("abc\n".matches("abc\\z\\n")); // false
    System.out.println("abc\n".matches("abc\\n\\z")); // true

      Modified On Apr-03-2018 04:25:31 AM

Answer