Java Array Sort sortByLength(String[] proposals)

Here you can find the source of sortByLength(String[] proposals)

Description

sort By Length

License

Open Source License

Declaration

private static String[] sortByLength(String[] proposals) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000, 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/* w  ww .j a  v  a 2  s.  co m*/
 *     IBM Corporation - initial API and implementation
 *     John Kaplan, johnkaplantech@gmail.com - 108071 [code templates] template for body of newly created class
 *******************************************************************************/

import java.util.Arrays;

import java.util.Comparator;

public class Main {
    private static String[] sortByLength(String[] proposals) {
        Arrays.sort(proposals, new Comparator() {
            public int compare(Object o1, Object o2) {
                return ((String) o2).length() - ((String) o1).length();
            }
        });
        return proposals;
    }
}

Related

  1. sortArrayAndReturnIndex(double[] p, String t)
  2. sortByFirst(int[] array1, int[] array2)
  3. sortByIndex(final double[] data, int size)
  4. sortByIndex(int start, int end, int[] indexes, double[] values)
  5. sortByIndex(int start, int end, int[] indexes, double[] values)
  6. sortByLengthDesc(String[] ss)
  7. sortByString(Object[] array)
  8. sortByValue(int start, int end, double[] values, int[] indexes)
  9. sortByValueStable(int start, int end, double[] values, int[] indexes)