mirror of
https://gitee.com/dromara/hutool.git
synced 2025-11-24 08:33:22 +08:00
@@ -486,7 +486,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
||||
if(index < 0){
|
||||
index = this.position + index;
|
||||
}
|
||||
if ((index < 0) || (index > this.position)) {
|
||||
if ((index < 0) || (index >= this.position)) {
|
||||
throw new StringIndexOutOfBoundsException(index);
|
||||
}
|
||||
return this.value[index];
|
||||
|
||||
@@ -131,4 +131,13 @@ public class StrBuilderTest {
|
||||
helloWorld.insert(6, "Beautiful ");
|
||||
Assertions.assertEquals("Hello Beautiful World", helloWorld.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void charAtTest() {
|
||||
final StrBuilder helloWorld = StrBuilder.create("Hello World");
|
||||
Assertions.assertEquals(helloWorld.charAt(-1),'d');
|
||||
Assertions.assertEquals(helloWorld.charAt(0),'H');
|
||||
Assertions.assertEquals(helloWorld.charAt(10),'d');
|
||||
Assertions.assertThrows(StringIndexOutOfBoundsException.class, () -> helloWorld.charAt(11));;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user