Java enum utilization and regular expression questions.

Asked 2 years ago, Updated 2 years ago, 85 views

within the enum class When input char comes in, use the regular expression Returns the appropriate enum value The task of implementing a function.

There are only examples of string types. It was weird, so I asked if the input is in the form of a string They said to leave the input in char Is there any way to do it with a Char type?

public enum MyType{
    Type1, Type2, Type3;

     static MyType getMyType(char keyword){
        ...
        switch(keyword){
        case ' [a-zA-Z0-9]* ' : return Type1;
        case ' "not" ' : return Type2; 
        //  The string "[a-zA-Z0-9]*" typeis2" 
        How do you treat a keyword as a char variable?
        ....
        ..
        .
    }
}
}

java-8 java parsing

2022-09-22 19:37

1 Answers

If keyword is a character, the above code is a strange code.

You don't have to use quantifier, and the keyword won't match the letter not.

Did the questioner misunderstand the assignment, or was it an assistant? I think you answered wrong


2022-09-22 19:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.