I am separating a word in Java whose separator is a -, my problem is that sometimes it does not have - to separate and therefore it gives me an error, as it could previously detect that the separator does not exist. An example so that it is understood: That is, it works correctly like this
String palabra="hola-adios";
But if I pass through the Split a string without a separator like the following, there is an exception:
String palabra2="hola";
Strings in java have a method called contains, which returns a boolean value if the string contains another...
You could use it this way:
It uses the method
contains()
of the classString
that allows you to know if a string contains another one inside.