Advertise with us

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

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.

Last updated:10/14/2013 3:59:06 AM

1 Answers

Kate Smith
Kate Smith

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

Answer