I want to print inverted quotes in java. But how to print it?
for(int i=0;i<hello.length;i++) {
String s=hello[i].toLowerCase().trim();
System.out.println(""+s+"");
}
expected OP: "hi".....
I want to print inverted quotes in java. But how to print it?
for(int i=0;i<hello.length;i++) {
String s=hello[i].toLowerCase().trim();
System.out.println(""+s+"");
}
expected OP: "hi".....
Because double quotes delimit String values, naturally you must escape them to code a literal double quote, however you can do it without escaping like this:
System.out.println('"' + s + '"');
Here, the double quote characters ("
) have been coded as char
values. I find this style easier and cleaner to read than the "clumsy" backslashing approach. However, this approach may only be used when a single character constant is being appended, because a 'char' is (of course) exactly one character.
As quotes are used in the Java source code to represent a string, you need to escape them to create a string that contains a quote
System.out.println("\""+s+"\"");
Assuming that by "Inverted" quotes you meant "Left" and "Right" specific quotation marks, you could do it like this:
System.out.println('\u201C'+s+'\u201D'); // Prints: “s”
System.out.println('"'+s+'"'); // Prints: "s"
If you are really looking for inverted quotes, use this:
System.out.println('\u201C' + s + '\u201D');
It'll output “hi”
, not "hi"
.
You need to have a font installed, though, that supports this, otherwise you might get a box or something instead. Most Windows fonts do.