How to resolve Invalid escape sequence in Java?

How can I use back slashes for a string in Java?

For example:

myString = "run -u A \\msomething\hsomething\something\something done";

Open in new window

It underlines the whole string in read it says:

Invalid escape sequence (valid ones are  \b  \t  \n  \f  \r  \"  \'  \\ )

Open in new window

I solved the problem by doing the following but I am looking for a more elegant solution:

myString = "run -u A" + "\\\\" + "msomething" + "\\" + "hsomething" + "\\" + "something" + "\\" + "something done";

Open in new window

Who is Participating?
ozoConnect With a Mentor Commented:
myString = "run -u A\\\\msomething\\hsomething\\something\\something done";
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.