I'm considering how to refactor code to make it clean & clear.There are some principles to make code clean; in this case I think it's Single Responsibility and One level of abstraction.The original code is like this:for (int i = 0; i < header.length; i++) {  if (header[i].equals(Constant.ID)) {    indexOfID = i;  } else if (header[i].equals(Constant.NAME)) {    indexOfName = i;  } else if (header[i].equals(Constant.CATEGORY)) {    indexOfCategory = i;  }}Then I separated the loop into smaller functions.private int getIndexOfColumnType(String[] header, String type) {  int index = -1;  int i = 0;  int size = header.length;  while (index < size && index < 0) {    if(header[i].equals(type)) {      index = i;    }    i++;  }  return index;}And call itint indexOfID = getIndexOfColumnType(header, Constant.ID);int indexOfName = getIndexOfColumnType(header, Constant.NAME);int indexOfCategory = getIndexOfColumnType(header, Constant.CATEGORY);In this way, I need to use 3 loops; so I wonder which is better for performancebecause header array can be large.Please tell me your idea.
Finding the array indices of three specific headers
java;performance;array;comparative review