javaregexstring-matching

using java , what are the methods to find a word inside a string?


if i have a string str that is: a>b
what is the best way to find if string str has a > ?do i use:

delimiter =">"
str.split(delimter)

or

str.contains(">")

or regular expression? actually i would prefer using regular expression, how to use regular expression in this case?

thanks for the help


Solution

  • It would be

    System.out.println("a>b".matches(".*>.*"));
    

    But in this case, I would just go with contains