if (Input.startsWith("USER ")) { ...
Is it possible to only check the first four letters of a string during: input.equals("USER test"); JAVA POP3
質問
I'm trying to make a mail system with POP3 commands using java.
When a user logs in, they enter "USER" followed by their username e.g "USER ben"
in order to send them along their way I was wondering if here:
import java.util.Scanner;
public class TestingPart1 {
public static void main(String[]args){
int on = 1;
while (on == 1){
System.out.println("+OK POP3 server ready");
Scanner answer = new Scanner(System.in);
String Input = answer.nextLine();
**if (Input.equals.("USER test")){
CommandInterpreter.handleUser(Input);
}**
I would be able to only check the first four characters USER so that when it gets passed through to CommandInterpreter it still reads USER test, but passes this stage
thanks :)
解決
他のヒント
You can use a split with a space into a string array. Then evaluate whether the first element of the array is equal to "USER"
Input is unchanged by the split operation.
所属していません StackOverflow