fix String#join, rm producing extra zero characters

This commit is contained in:
Alexander Gusakov 2019-11-07 17:14:14 +03:00 committed by Alexey Andreev
parent 099b9c5827
commit 74ee848e0c
2 changed files with 22 additions and 1 deletions

View File

@ -667,7 +667,7 @@ public class TString extends TObject implements TSerializable, TComparable<TStri
for (CharSequence element : elements) { for (CharSequence element : elements) {
resultLength += element.length(); resultLength += element.length();
} }
resultLength += elements.length * delimiter.length(); resultLength += (elements.length - 1) * delimiter.length();
char[] chars = new char[resultLength]; char[] chars = new char[resultLength];
int index = 0; int index = 0;

View File

@ -290,4 +290,25 @@ public class StringTest {
public void internsConstants() { public void internsConstants() {
assertSame("abc", ("a" + "bc").intern()); assertSame("abc", ("a" + "bc").intern());
} }
@Test
public void joinStrings() {
String str = String.join("/", "a", "b");
assertEquals(3, str.length());
assertEquals("a/b", str);
}
@Test
public void joinSingleString() {
String str = String.join("/", "a");
assertEquals(1, str.length());
assertEquals("a", str);
}
@Test
public void joinNoStrings() {
String str = String.join("/");
assertEquals(0, str.length());
assertEquals("", str);
}
} }