The. This section briefly describes the following algorithms:.
The following
trivial program prints out its arguments in lexicographic (alphabetical) order.
import java.util.*; public class Sort { public static void main(String[] args) { List<String> list = Arrays.asList(args); Collections.sort(list); System.out.println(list); } }: [palest, palets, pastel, petals, plates, pleats, septal, staple, tepals] 9: [anestri, antsier, nastier, ratines, retains, retinas, retsina, stainer, stearin] 8: [lapse, leaps, pales, peals, pleas, salep, sepal, spale] 8: [aspers, parses, passer, prases, repass, spares, sparse, spears] 8: [enters, nester, renest, rentes, resent, tenser, ternes,��treens] 8: [arles, earls, lares, laser, lears, rales, reals, seral] 8: [earings, erasing, gainers, reagins, regains, reginas, searing, seringa] 8: [peris, piers, pries, prise, ripes, speir, spier, spire] 8: [ates, east, eats, etas, sate, seat, seta, teas] 8: [carets, cartes, caster, caters, crates, reacts, recast,��traces]
The
shuffle algorithm does the opposite of what
sort does, destroying any trace of order that may have been present in a
List. That is,: one takes a
List and uses a default source of randomness, and the other requires the caller to provide a
Random object to use as a source of randomness. The code for this algorithm is used as an example in the
List section., or(list, key); if (pos < 0) l.add(-pos-1, key);.