I'm trying to figure out if there is something wrong with the way I'm creating Object arrays in my code, or if handling Object arrays in Java is more expensive than I originally thought it was.

I have a simple enum class called `ElementaryTransitionTerm`, consisting of ony two primitive member variables. A method in another class creates an array consisting of a combination of this Enum's constants (with the possible length of the array never exceeding 3). 

The problem is that in total, the program spends (on average) **13ms** inside said method, though it is **called only 8 times**. I have no idea why. 

Running times were calculated 2 ways:

1. Surrounding the call to the method by System.nanoTime() calls.
2. Surrounding each array creation statement inside the method by
System.nanoTime() calls and summing them up

Here is the **ElementaryTransitionTerm** enum class:

```
public enum ElementaryTransitionTerm 
{
    MATCH(1, 0), INSERTION(0, 1), SUBSTITUTION(1, 1), DELETION(0, 0), FAILURE(0, 0);

    private final int I_OFFSET;
    private final int E_OFFSET;

    private ElementaryTransitionTerm(int iOffset, int eOffset)
    {
        I_OFFSET = iOffset;
        E_OFFSET = eOffset;

    }
}

```

Here is the method in question, **createTransitionTerms** (as well as the declaration of the enum type used as a parameter):

```
//'E' and 'I' are both private int fields in the parent class.

private enum RelevantSubwordHitIndexType { FIRST_INDEX, TRAILING_INDEX, NO_INDEX };

/**
 * Creates an array of ElementaryTransitionTerm constants.

 * @param hitIndexType     a RelevantSubwordHitIndexType enum constant
 */
private ElementaryTransitionTerm[] createTransitionTerms(RelevantSubwordHitIndexType hitIndexType)
{
    //Simple getter method chained in to String.length() call
    int onePastFinalBoundary = parentAutomaton.getAutomatonString().length(); 

    if(E < parentAutomaton.getMaxEditDistance())   //Simple getter method retrieving an int
    {
        if(I < onePastFinalBoundary - 1)           
        {
            switch(hitIndexType)
            {
                case FIRST_INDEX:       return new ElementaryTransitionTerm[] {ElementaryTransitionTerm.MATCH};
                case TRAILING_INDEX:    return new ElementaryTransitionTerm[] {ElementaryTransitionTerm.INSERTION, ElementaryTransitionTerm.SUBSTITUTION, ElementaryTransitionTerm.DELETION};
                default:                return new ElementaryTransitionTerm[] {ElementaryTransitionTerm.INSERTION, ElementaryTransitionTerm.SUBSTITUTION};
            }
        }
        else if(I == onePastFinalBoundary - 1)     
        {
            switch(hitIndexType)
            {
                case FIRST_INDEX:       return new ElementaryTransitionTerm[] {ElementaryTransitionTerm.MATCH};
                default:                return new ElementaryTransitionTerm[] {ElementaryTransitionTerm.INSERTION, ElementaryTransitionTerm.SUBSTITUTION};
            }
        }
        else                            return new ElementaryTransitionTerm[] {ElementaryTransitionTerm.INSERTION};     
    else                                            
    {
        if(I < onePastFinalBoundary)                
        {
            switch(hitIndexType)
            {
                case FIRST_INDEX:       return new ElementaryTransitionTerm[] {ElementaryTransitionTerm.MATCH};
                default:                return new ElementaryTransitionTerm[] {ElementaryTransitionTerm.FAILURE};
            }
        }
        else                            return new ElementaryTransitionTerm[] {ElementaryTransitionTerm.FAILURE};
    }
}

```

The method essentially evaluates a small set of conditionals in order to create a small array. However, the total execution time of 8 runs of this method does not reflect that.

I've even gone so far as to declare the to-be-returned arrays as `public final` arrays in ElementaryTransitionTerm, and replace the creation statements in the above methods with references to these arrays, but it has absolutely no effect on the code's running time.

I've written code that does more in less time. So I'm curious as to why this method is behaving like this. Does anyone have any ideas?

**EDIT**:

After further testing, i've discovered a two things:

1. Testing the method in isolation yields expected (i.e
sub-millisecond) results.
2. Testing the method within the program, it seems as though whichever
array creation statement is executed on the first call to the
function is essentially responsible for the times i'm seeing. All
subsequent calls complete in sub-millisecond times.

Concerning #2: What is the reason for this, and how can I go about rectifying it?