Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this slower ???


than this ???

 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic