I need to create a class with exactly the same methods as java.lang.String
.
What is the best way to do this in Java?
I know that I can't extend String class as it is final
. I am not looking at solutions where I need to copy the source code of java.lang.String
. For example, assume that I need the functionality length()
within my custom class named MyString
, which has a corresponding 'myLength()` method.
What is the best way to implement myLength()
?
I am not looking at various algorithms to find out the length of a string but to reuse String
's length()
method. Now once I have MyString
class ready, I should be able to use it anywhere for my custom manipulations.