Does Pattern.compile cache?

As far as I know from looking at the code (JDK 6) it doesn’t do caching but once constructed, Pattern object could be cached on application side and shared among multiple threads. Standard pattern seems to be to assign it to final static variable:

private static final Pattern p = Pattern.compile(",");

Leave a Comment