Java examples for Collection Framework:Array Sort
generate sorted array
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { int length = 2; System.out.println(java.util.Arrays .toString(generateSortedArray(length))); }// ww w . j ava 2 s .com /** * generate sorted array */ public static int[] generateSortedArray(int length) { if (length <= 0) { return new int[] {}; } int[] arr = new int[length]; int data = 1; for (int i = 0; i < length; i++) { arr[i] = data++; // data += RandomUtil.randomIntIn(3); } return arr; } }