Question: in Java I am trying to split a 1d array of strings. First I had to read a text and store it into a 1d
in Java
I am trying to split a 1d array of strings.
First I had to read a text and store it into a 1d array but it also is separated by spaces in one line.
These strings also have different lenghths BUT they MUST be in the same 1d array.
Right now my program only outputs:
newArray[1] = ["This is a test"];
what it should be is:
newArray[0] = ["A", "different", "length"];
newArray[1] = ["This", "is", "a", "test"];
I guess I should be using split, but I am not sure how to use it for this 1d array.
DO NOT USE builded in codes. Please use manual codes if that makes sense.
Code:
java.util.Arrays;
public class Test
public static void main(String[] args)
String[] newArray = new String[2];
String one = "A different length";
String two = "This is a test";
newArray[0] = one;
newArray[1] = two;
System.out.println(Arrays.toString(newArray));
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
