Performance replacement for String in Java [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this questionAnyone remembers the name of that opensource "project" that develope开发者_如何学运维d some nice replacement for String in java ?
I know there is is one, just cant find it in google and dont remember the name. (i am not talking about StringBuilder)
Thanks
Are you looking for ropes?
A rope is a high performance replacement for Strings. The datastructure, described in detail in "Ropes: an Alternative to Strings", provides asymptotically better performance than both String and StringBuffer for common string modifications like prepend, append, delete, and insert. Like Strings, ropes are immutable and therefore well-suited for use in multi-threaded programming.
There isn't a better general-purpose replacement. Java's String class is extremely well implemented for general purpose use.
There are better implementations for specific cases that might help you in certain circumstances:
- Ropes allow cheap concatenation of large strings since they exploit a shared tree structure. Possibly better than Strings if most of your CPU time is spent on concatenating large strings. Ropes also contains some nice optimisations for large blocks of repeated characters and similar. They are not particularly efficient for general purpose use however.
- javolution.text.Text is similar in concept to Ropes, but is more lightweight and supports custom memory allocation for realtime usage. If you are doing realtime work with large strings this may be the best fit for you.
- mikera.persistent.Text is my own immutable text implementation. Very fast, similar in concept to javolution.text.Text but has precomputed hashcodes so will be better if you want to use large strings as hashmap or hashset keys. (I needed this at some point, hence I rolled my own...)
- StringBuilder is very good if you want a mutable string that you are going to do a lot of small changes to.
- char[] array is simple and pretty good if all you want is a mutable string of fixed length - it's pretty much the most efficient you can do on the JVM. Worth considering if you are trying to implement some custom low-level string algorithm. Most other string implementations use this under the hood.....
Maybe Javolution and its javolution.text.Text
?
精彩评论