java get longest string in array

Solutions on MaxInterview for java get longest string in array by the best coders in the world

showing results for - "java get longest string in array"
Thiago
20 Aug 2018
1int index = 0; 
2int elementLength = array[0].length();
3for(int i=1; i< array.length(); i++) {
4    if(array[i].length() > elementLength) {
5        index = i; elementLength = array[i].length();
6    }
7}
8return array[index];
9