當前位置: 首頁>>代碼示例>>Java>>正文


Java Arrays.sort方法代碼示例

本文整理匯總了Java中java.util.Arrays.sort方法的典型用法代碼示例。如果您正苦於以下問題:Java Arrays.sort方法的具體用法?Java Arrays.sort怎麽用?Java Arrays.sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Arrays的用法示例。


在下文中一共展示了Arrays.sort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: SerializablePrincipal

import java.util.Arrays; //導入方法依賴的package包/類
/**
 * Construct a new Principal, associated with the specified Realm, for the
 * specified username and password, with the specified role names (as
 * Strings).
 *
 * @param name
 *            The username of the user represented by this Principal
 * @param password
 *            Credentials used to authenticate this user
 * @param roles
 *            List of roles (must be Strings) possessed by this user
 * @param userPrincipal
 *            The user principal to be exposed to applications
 */
public SerializablePrincipal(String name, String password, List<String> roles, Principal userPrincipal) {

	super();
	this.name = name;
	this.password = password;
	if (roles != null) {
		this.roles = new String[roles.size()];
		this.roles = roles.toArray(this.roles);
		if (this.roles.length > 1)
			Arrays.sort(this.roles);
	}
	if (userPrincipal instanceof Serializable) {
		this.userPrincipal = userPrincipal;
	}
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:30,代碼來源:SerializablePrincipal.java

示例2: doTestSetTextNonContiguous

import java.util.Arrays; //導入方法依賴的package包/類
public void doTestSetTextNonContiguous() {
    System.err.println("testSetTextNonContiguous");
    String[] names = new String [5];
    int[] indices = new int[] {22,11,15,8,3};
    for (int i=0; i < names.length; i++) {
        names[i] = mdl.getTab(indices[i]).getText();
    }
    noEvent = true;
    //should produce no event since the names haven't changed
    mdl.setText(indices, names);
    noEvent = false;
    String[] s = new String[names.length];
    for (int i=0; i < s.length; i++) {
        s[i] = names[i] + "modified";
    }
    mdl.setText(indices, s);
    for (int i=0; i < s.length; i++) {
        assertText(s[i], indices[i]);
    }
    Arrays.sort (indices);
    assertEventIndices(indices);
    assertListenerCall("contentsChanged");
    assertWidthChanged();
    //restore the original text
    mdl.setText(indices, names);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:DataModelTest.java

示例3: sortRowWhite

import java.util.Arrays; //導入方法依賴的package包/類
static int[] sortRowWhite(int[] pixels, int currentRow, int width) {
    int y = currentRow;
    int x = 0;
    int xe = 0;
    while (xe < width - 1) {
        x = White.getFirstNotWhiteX(pixels, x, y, width);
        xe = White.getNextWhiteX(pixels, x, y, width);
        if (x < 0) {
            break;
        }
        int sortedLength = xe - x;
        int[] sorted = new int[sortedLength];
        for (int i = 0; i < sortedLength; i++) {
            sorted[i] = pixels[x + i + y * width];
        }
        Arrays.sort(sorted);
        for (int i = 0; i < sortedLength; i++) {
            pixels[x + i + y * width] = sorted[i];
        }
        x = xe + 1;
    }
    return pixels;
}
 
開發者ID:vshkl,項目名稱:PXLSRT,代碼行數:24,代碼來源:PixelSort.java

示例4: retainAll

import java.util.Arrays; //導入方法依賴的package包/類
/** {@inheritDoc} */
public boolean retainAll( int[] array ) {
    boolean changed = false;
    Arrays.sort( array );
    int[] set = _set;
    byte[] states = _states;

    _autoCompactTemporaryDisable = true;
    for ( int i = set.length; i-- > 0; ) {
        if ( states[i] == FULL && ( Arrays.binarySearch( array, set[i] ) < 0) ) {
            removeAt( i );
            changed = true;
        }
    }
    _autoCompactTemporaryDisable = false;

    return changed;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:19,代碼來源:TIntHashSet.java

示例5: sortConstructors

import java.util.Arrays; //導入方法依賴的package包/類
/**
 * Sort the given constructors, preferring public constructors and "greedy" ones with
 * a maximum number of arguments. The result will contain public constructors first,
 * with decreasing number of arguments, then non-public constructors, again with
 * decreasing number of arguments.
 * @param constructors the constructor array to sort
 */
public static void sortConstructors(Constructor<?>[] constructors) {
	Arrays.sort(constructors, new Comparator<Constructor<?>>() {
		@Override
		public int compare(Constructor<?> c1, Constructor<?> c2) {
			boolean p1 = Modifier.isPublic(c1.getModifiers());
			boolean p2 = Modifier.isPublic(c2.getModifiers());
			if (p1 != p2) {
				return (p1 ? -1 : 1);
			}
			int c1pl = c1.getParameterTypes().length;
			int c2pl = c2.getParameterTypes().length;
			return (new Integer(c1pl)).compareTo(c2pl) * -1;
		}
	});
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:AutowireUtils.java

示例6: toArray

import java.util.Arrays; //導入方法依賴的package包/類
@Test
public void toArray() throws Exception {
	TreeMap<CartesianPoint, String> map = new TreeMap<>(TreeMap.Space2D);
	for (int i = 0; i < 50; i++) {
		map.put(new CartesianPoint(i, i), Integer.toString(i * i));
	}
	Object[] objects = map.values().toArray();
	Arrays.sort(objects);
	for (int i = 0; i < 50; i++) {
		assertTrue(Arrays.binarySearch(objects, Integer.toString(i * i)) >= 0);
	}
}
 
開發者ID:highpower,項目名稱:java-kdtree,代碼行數:13,代碼來源:ValueCollectionTest.java

示例7: checkRange

import java.util.Arrays; //導入方法依賴的package包/類
private static void checkRange(int[] a, int m) {
    try {
        Arrays.sort(a, m + 1, m);

        failed("Sort does not throw IllegalArgumentException " +
            " as expected: fromIndex = " + (m + 1) +
            " toIndex = " + m);
    }
    catch (IllegalArgumentException iae) {
        try {
            Arrays.sort(a, -m, a.length);

            failed("Sort does not throw ArrayIndexOutOfBoundsException " +
                " as expected: fromIndex = " + (-m));
        }
        catch (ArrayIndexOutOfBoundsException aoe) {
            try {
                Arrays.sort(a, 0, a.length + m);

                failed("Sort does not throw ArrayIndexOutOfBoundsException " +
                    " as expected: toIndex = " + (a.length + m));
            }
            catch (ArrayIndexOutOfBoundsException aie) {
                return;
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:Sorting.java

示例8: sortStringArray

import java.util.Arrays; //導入方法依賴的package包/類
/**
 * Turn given source {@code String} array into sorted array.
 * @param array the source array
 * @return the sorted array (never {@code null})
 */
public static String[] sortStringArray(String[] array) { 
	if (ObjectUtils.isEmpty(array)) {
		return new String[0];
	}

	Arrays.sort(array);
	return array;
}
 
開發者ID:drinkjava2,項目名稱:jDialects,代碼行數:14,代碼來源:StringUtils.java

示例9: commandLineRunner

import java.util.Arrays; //導入方法依賴的package包/類
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
    return args -> {

        System.out.println("Let's inspect the beans provided by Spring Boot:\n");

        String[] beanNames = ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        for (String beanName : beanNames) {
            System.out.println(beanName);
        }

        System.out.println("---");
    };
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:16,代碼來源:CalendarApplication.java

示例10: maybeSort

import java.util.Arrays; //導入方法依賴的package包/類
/** Clone and sort the array, if not already sorted. */
private static
int[] maybeSort(int[] values) {
    if (!isSorted(values, 0, false)) {
        values = values.clone();
        Arrays.sort(values);
    }
    return values;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:Histogram.java

示例11: arraysSortNoComparator

import java.util.Arrays; //導入方法依賴的package包/類
@Benchmark int arraysSortNoComparator(int reps) {
  int tmp = 0;
  for (int i = 0; i < reps; i++) {
    Integer[] copy = inputArrays[i & 0xFF].clone();
    Arrays.sort(copy);
    tmp += copy[0];
  }
  return tmp;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:10,代碼來源:ComparatorDelegationOverheadBenchmark.java

示例12: testDescendingToArray

import java.util.Arrays; //導入方法依賴的package包/類
/**
 * toArray contains all elements
 */
public void testDescendingToArray() {
    NavigableSet q = populatedSet(SIZE);
    Object[] o = q.toArray();
    Arrays.sort(o);
    for (int i = 0; i < o.length; i++)
        assertEquals(o[i], q.pollFirst());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:TreeSubSetTest.java

示例13: remove

import java.util.Arrays; //導入方法依賴的package包/類
/**
 * Removes the.
 *
 * @param maxFileCount
 *            the max file count
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private void remove(int maxFileCount) throws IOException {
	File dir = new File(metricPath);
	FilenameFilter promFileFilter = (f, s) -> s.endsWith(".prom");
	File[] directoryListing = dir.listFiles(promFileFilter);
	if (directoryListing != null) {
		Arrays.sort(directoryListing);
		for (int i = 0; i < directoryListing.length - maxFileCount; i++) {
			directoryListing[i].delete();
		}
	} else {
		throw new IOException("Directory not listable: " + metricPath);
	}
}
 
開發者ID:mevdschee,項目名稱:tqdev-metrics,代碼行數:22,代碼來源:PrometheusLogReporter.java

示例14: sort

import java.util.Arrays; //導入方法依賴的package包/類
private void sort() {
    for (int i = 0; i < vectorBuff.size(); i++)
        data.add(vectorBuff.get(i));
    buff = data.toArray();
    Arrays.sort(buff);
    vectorBuff.clear();
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:8,代碼來源:FastMatrixProjection.java

示例15: calculateMeanSigma

import java.util.Arrays; //導入方法依賴的package包/類
private HashMap<String, Tupel<Double, Double>> calculateMeanSigma(ExampleSet exampleSet) {
	HashMap<String, Tupel<Double, Double>> attributeMeanSigmaMap = new HashMap<String, Tupel<Double, Double>>();

	for (Attribute attribute : exampleSet.getAttributes()) {
		if (attribute.isNumerical()) {
			double values[] = new double[exampleSet.size()];
			int i = 0;
			for (Example example : exampleSet) {
				values[i++] = example.getValue(attribute);
			}

			Arrays.sort(values);

			int lowerQuart = (int) (((values.length + 1) * 0.25) - 1);
			int upperQuart = (int) (((values.length + 1) * 0.75) - 1);

			double iqSigma = (values[upperQuart] - values[lowerQuart]) / 1.349;
			double median = 0;

			if (0 == (exampleSet.size() % 2)) {
				if (exampleSet.size() > 1) {
					median = (values[exampleSet.size() / 2] + values[(exampleSet.size() / 2) - 1]) / 2;
				}
			} else {
				median = values[exampleSet.size() / 2];
			}

			attributeMeanSigmaMap.put(attribute.getName(), new Tupel<Double, Double>(median, iqSigma));
		}
	}
	return attributeMeanSigmaMap;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:33,代碼來源:IQRNormalizationMethod.java


注:本文中的java.util.Arrays.sort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。