0
How to "split" and "join" string in java
in javascript, we can turn a string to an array by using "split" method. exampel : var a = "Hello world"; var b = a.split(''); document.write(b); //output = H,e,l,l,o, ,w,o,r,l,d or join method : var a = [1,2,3,4,5,6,7]; var b = a.join(''); document.write(b); //output = 1234567 what method should i use to Split or Join string in Java ??
2 Answers
+ 2
"thing".split("")
String.join("", array)
0
public void whenJoiningTwoArrays_thenJoined() {
String[] animals1 = new String[] { "Dog", "Cat" };
String[] animals2 = new String[] { "Bird", "Cow" };
String[] result = Stream.concat(
Arrays.stream(animals1), Arrays.stream(animals2)).toArray(String[]::new);
assertArrayEquals(result, new String[] { "Dog", "Cat", "Bird", "Cow" });
}