I want to store \ in a string variable #
String var= "\" ;
public class Main
{
public static void main(String[] args) {
String var="\"
System.out.println(var);
}
}
String var= "\" ;
public class Main
{
public static void main(String[] args) {
String var="\"
System.out.println(var);
}
}
From Characters
A character preceded by a backslash (\) is an escape sequence and has special meaning to the compiler. The following table shows the Java escape sequences:
\\ Insert a backslash character in the text at this point.
So in you case use below code:
String var = "\\";