Question: Hey this code works just fine, but it is difficult to read. I am looking for a way to do this better.

```
public void printArray(String[/*row*/][/*column*/] twoDiArray) {
    if (twoDiArray.length == 2) {
        for (int i = 0; i < twoDiArray[0].length; i++) {
            //prints attribute name and value
            attributeNameAndValue(twoDiArray[0][i],twoDiArray[1][i]);
        }
    } else {
        System.out.println("Does not fit format standards :: 2d array :: two rows max :: first row name :: second row value");
    }
}

```

The part I seriously dislike is the length calls in the if statement and the for loop. Is there a better way to do this or is it just a sloppy section of java language.

Answer: 
You have pairs name-value, if your names are unique, you should use `Map<String, Integer>` instead. Otherwise, create your own class called e.g. `Attribute` and use `List<Attribute>`:

```
public class Attribute {

    private final String name;
    private final int value;

    public Attribute(String name, int value) {
        this.name = name;
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public int getValue() {
        return value;
    }

}

```

This gives you compile-time safety for the second dimension. Your code would look like this:

```
public void printArray(List<Attribute> attributes) {
    for (Attribute attribute : attributes) {
        attributeNameAndValue(attribute.getName(), attribute.getValue());
    }
}

```
another way to check array

```
public void printArray(String[/*row*/][/*column*/] twoDiArray){
  assert twoDiArray.length == 2;
  for(int i=0; i<twoDiArray[0].length; i++){
    attributeNameAndValue(kvp[i][0], kvp[i][1]);
  }
}

```