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.
Asked
Active
Viewed 2.7k times
-3
-
1this is really 2 questions. Both of which probably already have answers here on SO. – Zach Lysobey Dec 01 '13 at 20:36
-
http://stackoverflow.com/questions/14945656/list-an-array-of-strings-in-alphabetical-order – But I'm Not A Wrapper Class Dec 01 '13 at 20:36
-
@peter I think he's having problems writing a proper question :/ – Bohemian Dec 01 '13 at 20:37
-
@Bohemian Your guess is as good as mine. – Peter Lawrey Dec 01 '13 at 20:41
2 Answers
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