java重载的StringBuilder insert()以及偏移量和索引之间的差异
我只是想知道,在指示可以插入指定参数的位置时,偏移量和索引的语义是否有任何区别(可以是String、Object、char[]等类型)。例如,所有两个参数insert()重载方法都将该位置称为“offset”。然而,这一点:
public StringBuilder insert(int index, char[] str, int offset, int len)
使用“索引”来指代字符串中发生插入的位置。 从技术上讲,我认为正确的术语应该是“offset”,但我只是想知道,为什么类设计人员在基本上相同的操作中使用了两个不同的术语
谢谢
# 1 楼答案
从javadoc
所以:
offset
与str
相关,即您要添加到StringBuilder
内容中的char[]
index
与StringBuilder
中的实际内容相关特别是javadoc:
下面是一个示例代码: