aspose file tools
The moose likes Performance and the fly likes is matches() slower than the char array check in String validation? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Performance
Reply Bookmark "is matches() slower than the char array check in String validation?" Watch "is matches() slower than the char array check in String validation?" New topic
Author

is matches() slower than the char array check in String validation?

Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

is this slower ???


than this ???



Time is what we want the most, but what we use the worst. -- William Penn
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 852
1) I suspect this would never be a bottleneck in a real application so it makes more sense to do which makes your vailidation the most flexible and easiest to maintain. Either way I would come up with a validate(...) method and hide the implementation.
2) If you really want to see performance differences run a lot of validations and time each approach.
3) You can also look at the source code. Here is a good site that has the java source. String.matches calls Pattern.matches. http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Core/Collections-Jar-Zip-Logging-regex/java/util/regex/Pattern.java.htm


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4422
    
    2

Robin John wrote:


Does your code work internationally? Its probably fine for ASCII, but the A in ASCII is American.

A major point of the generalized pattern stuff is to fit well into international code, I tend to think that languages such as Arabic or Tamil are not going to use American digits.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is matches() slower than the char array check in String validation?
 
Similar Threads
Splitting Between String and Numbers
Old COBOL dude needs direction
why does it tell me that there is else without if (java programming)?
How to get or replace the backslash in Java string
Finding out number of digits in a String