I have a string[] = [5 5, 1 2 N, LMLMLMLMM, 3 3 E, MMRMMRMRRM]
When I split the 2nd and 4th elements. I get
[, L, M, L, M, L, M, L, M, M]
[, M, M, R, M, M, R, M, R, R, M]
import java.io.*;
public class Instruction {
public String[] instructionList;
public String filePath;
public Instruction(String fileName) {
this.filePath = fileName;
}
public String[] readFile() throws IOException {
FileInputStream in = new FileInputStream(this.filePath);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
int n = 5;
instructionList = new String[n];
for (int j = 0; j < instructionList.length; j++) {
instructionList[j] = br.readLine();
}
in.close();
return instructionList;
}}
import java.util.Arrays;
public class RoverCommand {
public static void main(String[] args) throws Exception {
//Create new Instruction object with directions.txt.
Instruction directions = new Instruction("directions.txt");
String[] instructions = directions.readFile();
String roverInstructions = Arrays.toString(instructions[2].split(""));
System.out.println(roverInstructions);
}
I've tried replacing the empty space, to no avail. How can I split() without returning this empty first element?