-3

All I need to know is how to find the length of the string inside of the array. I also would like to know how to find which string comes first in alphabetical order in the array.

Zach Fortney
  • 39
  • 1
  • 2
  • 2

2 Answers2

5

myArr[0].length()

This will access the string at location 0, then get the length of it.

Also, for sorting alphabetically, you can use

Arrays.sort(myArr);

Alex
  • 1,100
  • 1
  • 9
  • 23
0

You can simply use .length method on any string array element to get its length, And to sort that array alphabetically you ca use .sort method -

For example -

String[] strings = { "Hello ", "This ", "is", "Sorting", "Example" };
Arrays.sort(strings);

So after sorting strings[0] would be Example and string[0].length() would be 7

Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111