On Tuesday, February 7, 2012 3:14:32 AM UTC-8, Mausam wrote:
>
http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#101089
That's the wrong document! Why are you citing ancient information? Get current.
http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html
> defines escape character for single character as well.
>
> But single quote works fine in String without any escape character.
>
> public class Class1 {
>
> private static String str = "I have a single quote. That's it";
> private static String str1 = "I have a single quote. That\'s it";
> public static void main(String[] args) {
> System.out.println(str);
> System.out.println(str1);
> }
> }
>
> How the two string is different?
Why do you claim that they're different?
> And when should I use escape character for single quote?
When you need to in order to make the expression mean what you intend.
--
Lew