implement length() of string without using Built-in functions

时间:2018-04-26 13:56:51

标签: java string

How can i get the length of a string in java without using any Built-in Functions neither using length() nor using any function

1 个答案:

答案 0 :(得分:0)

a)你可以序列化字符串并检查字节。(虽然其他一些类会调用String的函数。)

b)您可以将它发送到Writer子类,您可以在其中实现write(char [],int,int)(尽管,其他一些类也将调用String的函数。)

c)你可以尝试作弊并使用反射来拉取私有字段,并在它们上设置setAccessible(true)来拉取相关字段。注意,这是特定于JRE的,因此不能跨java版本移植。