I'm making my own Command line like windows command prompt or macs terminal. My plan was to have it take input(works) analysis it(does not work) and display it(works) then repeat.
This is the testing file for it
import java.util.Scanner;
public class addingStrings {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//Init
String out = "";
String input = scan.nextLine();
String component[] = input.split(" ");
for(int i = 0;i < component.length;i++) {
if(component[i] == "echo") {
i++;
while(component[i] != "\\") {
out += component[i];
i++;
}
}
}
System.out.println(out);
}
}
what it does is splits up the code into an array then checks each string in the array for a command such as echo or print. Once it finds one it would then print every thing after the echo command.
ex: it would read:
"echo Hello World \\"
split it into component = {"echo", "Hello", "World", "\"}
then check and find that component[0] is "echo" then display every thing until it hit \ and would display
Hello World
Every thing works except for the if statement. for some reason if i use an array like this
String[] component = {"echo", "Hello", "World"};
instead of splitting a String; it works fine.
Is there any way to make it read the split string array the same way as the normal array or does splitting a string to an Array output a string differently than directly saving values into an array.