Splitting a string into two halfs (#14500)

This commit is contained in:
Michael Olayemi 2023-07-31 01:31:30 +00:00 committed by GitHub
parent 92b922b6c1
commit 933571b813
1 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,19 @@
package com.baeldung.split;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class SplitIntoHalvesUnitTest {
@Test
public void givenAString_whenSplitInHalf_thenCorrectParts() {
String hello = "Baeldung";
int mid = hello.length() / 2;
String[] parts = { hello.substring(0, mid), hello.substring(mid) };
assertEquals("Bael", parts[0]);
assertEquals("dung", parts[1]);
}
}