7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Java 1.6系でStringSwitch

Posted at
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に無い文字列が含まれている場合の処理を記述
}
'''
7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?