Help us understand the problem. What is going on with this article?

Java 1.6系でStringSwitch

More than 5 years have passed since last update.
StringSwitch.java
enum TEST
{
    TEST1, TEST2, TEST3
};

String s = "TEST1";
TEST hogeVal = null;
try
{
    hogeVal = TEST.valueOf( s );
    switch( hogeVal )
    {
        case TEST1:
            // "TEST.TEST1"の処理
            break;
        case TEST2:
            // "TEST.TEST2"の処理
            break;
        case TEST3:
            // "TEST.TEST3"の処理
            break;
        default:
            break;
    }
}
catch( IllegalArgumentException ex )
{
    // enumに無い文字列が含まれている場合の処理を記述
}
'''
daitom
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away