Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java get longest string in array

int index = 0; 
int elementLength = array[0].length();
for(int i=1; i< array.length(); i++) {
    if(array[i].length() > elementLength) {
        index = i; elementLength = array[i].length();
    }
}
return array[index];
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #java #longest #string #array
ADD COMMENT
Topic
Name
6+4 =