I’m looking for a simpler solution. I’m new to Java and I need a little help. I’m trying to split String to String[] by this ‘],[‘. The problem is that Java tries to get these like a Regex and I don’t want to use it because I’m not good enough in it. I want just to split the string by these 3 characters “],[“;
Here is my code:
String usefulData = ...;
String[] list = null;
String token = "],[";
list = usefulData.split(token);
And here is the error ouput: Exception in thread “AWT-EventQueue-0” java.util.regex.PatternSyntaxException: Unclosed character class near index 2
],[… Please, any suggestions how to make this think works?
PS. Is there any other way to split the String? I don’t like this Regex very much. I have been used Qt and C# and in both places there is a way to escape from this Regular Expresions. Thanks a lot People!
You can build your String using
Pattern#quotemethod.That way you won’t have to
escapeyour special characters with a backslash.Pattern.quotemakes all yourspecial charactersin string behave like String literal: –OUTPUT: –