Array with enumerated elements Java program uses the following construction: (provided mainly for context)

public class Utils {
  public static final byte PROVIDER_FOO = 0;
  public static final byte PROVIDER_MOO = 1;
  public static final byte PROVIDER_BAR = 2;
  public static final byte PROVIDER_FUR = 3;
  public static final byte PROVIDER_BOO = 4;
  public static final byte PROVIDER_ANOTHER_FOO = 5;
  public static final byte PROVIDER_YET_ANOTHER = 6;

  public static String [] PROVIDERS = {"FOO", "MOO", "BAR", "FUR", "BOO",
    "PROVIDER_ANOTHER_FOO", "PROVIDER_YET_ANOTHER"};

  ...

}


So, each element of array has a number. And each array index in range 0..6 has text representation. Text representation is using in outer world: reading configs, printing results. Number representation is using in internal tasks. So, there a problem to transform text representation to number and vice versa. Number is transferring to string as following:

// someObject.getProviderNumeric() returns numeric value for someObj's provider
String strProvider = Utils.PROVIDERS[someObj.getProviderNumeric()] 


String is transferring to number like this:

int getNumericByText(String strProvider) {
  for (int i = 0; i &lt; Utils.PROVIDER_YET_ANOTHER; ++i) {
    if (strProvider.equals(Utils.PROVIDERS[i])) {
      return i;
  }
  return -1;
}


It looks pretty bulky. What is the best way to rewrite?
In my opinion, what you need is an enum.

Use an enum and I believe what you are looking for will be provided for you.

public enum Utils {
    PROVIDER_FOO, PROVIDER_MOO, PROVIDER_BAR, PROVIDER_FUR,
    PROVIDER_BOO, PROVIDER_ANOTHER_FOO, PROVIDER_YET_ANOTHER;
}


String to int:

Utils.valueOf(str).ordinal();


int to String:

Utils.values()[intValue].name();


Or if you want to be a bit more advanced, I suggest reading this answer of mine