0

配列と for ループを使用して、以下に示すデータベース変数をインスタンス化することは可能で、すべての行を入力する必要はありませんか?

 // example of one line only

 public static final String A0 = "a0";

何百行もある場合、これを改善する方法はありますか?

 public class DatabasePrototype {

    public static final String DATABASE_NAME = "database";
    public static final String SMALL_TANK_CHECK_RESULT = "small_tank_check_result";
    public static final String LARGE_TANK_CHECK_RESULT = "large_tank_check_result";

    public static final String CLEAN_TANK_RESULT = "clean_tank_result";
    public static final int DATABASE_VERSION = 1;
    public static final String _ID = "_id";

    // variables for LARGE_TANK_CHECK_RESULT
    public static final String A0 = "a0";
    public static final String A1 = "a1";
    public static final String A2 = "a2";
    public static final String A3 = "a3";
    public static final String A4 = "a4";
    public static final String A5 = "a5";
    public static final String A6 = "a6";
    public static final String A7 = "a7";
    public static final String A8 = "a8";
    public static final String A9 = "a9";
    public static final String A10 = "a10";
    public static final String A11 = "a11";
    public static final String A12 = "a12";
    public static final String A13 = "a13";
    public static final String A14 = "a14";
    public static final String A15 = "a15";
    public static final String A16 = "a16";
    public static final String A17 = "a17";
    public static final String A18 = "a18";
    public static final String A19 = "a19";
    public static final String A20 = "a20";
    public static final String A21 = "a21";
    public static final String A22 = "a22";
    public static final String A23 = "a23";
    public static final String A24 = "a24";
    public static final String A25 = "a25";
    public static final String A26 = "a26";
    public static final String A27 = "a27";
    public static final String A28 = "a28";
    public static final String A29 = "a29";
    public static final String A30 = "a30";
    public static final String A31 = "a31";
    public static final String A32 = "a32";
    public static final String A33 = "a33";
    public static final String A34 = "a34";
    public static final String A35 = "a35";
    public static final String A36 = "a36";
    public static final String A37 = "a37";
    public static final String A38 = "a38";
    public static final String A39 = "a39";
    public static final String A40 = "a40";
    public static final String A41 = "a41";
    public static final String A42 = "a42";
    public static final String A43 = "a43";
    public static final String A44 = "a44";
    public static final String A45 = "a45";
    public static final String A46 = "a46";
    public static final String A47 = "a47";
    public static final String A48 = "a48";
    public static final String A49 = "a49";
    public static final String A50 = "a50";
4

2 に答える 2

0
private static final String[] elems;


static
{
    elems = new String[table_elements];
    for(int i = 0; i < table_elements;i++)
    {
         elems[i] = "a"+i;
    }
}
于 2013-06-20T01:46:47.243 に答える