Home > Contents > Index >
Utilities.sortWords
Sorts a list of strings by length, from longest to shortest.
Syntax
public static final Vector sortWords(Vector words)Parameters
words
- Vector of strings.
Description
The
sortWords
method sorts a list of strings by length, from longest to shortest. A new vector is returned, leaving the original unchanged.Returns
New vector of strings (the original is untouched).
Example
The following code sorts a list of strings from the shortest to the longest:
Vector aVector = new Vector(); aVector.addElement("bear"); aVector.addElement("walrus"); aVector.addElement("cow"); aVector.addElement("llama"); Vector sortedVector = Utilities.sortWords(aVector);After executing the preceding code, the items in
sortedVector
are in the following order:
"cow" "bear" "llama" "walrus"
Home > Contents > Index > ![]()
Oracle JAVA Reference
Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.