Mike Mike - 1 year ago 97
Java Question

regex VS Contains. Best Performance?

I want to compare an URI String over different patterns in java and I want fastest code possible.

Should I use :

if(uri.contains("/br/fab") || uri.contains("/br/err") || uri.contains("/br/sts")

Or something like :


Note that I can have a lot more uri and this method is called very often.

What is the best answer between my choices ?

Answer Source

They're both fast enough to be over before you know it. I'd go for the one that you can read more easily.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download