According to Time complexity of Java's substring(), java's substring takes linear time. Is there a faster way (may be in some cases)? I may suggest iterator, but suspect that it also takes O(n).
val s1: String = s.iterator.drop(5).mkString
But several operations on an iterator would be faster than same operations on string, right?
If you need to edit very long string, consider using data structure called Rope.
Scalaz library has Cord class which is implementation of modified version of Rope.
A
Cord
is a purely functional data structure for efficiently storing and manipulatingString
s that are potentially very long. Very similar toRope[Char]
, but with better constant factors and a simpler interface since it's specialized forString
s.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加