Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Intermediate
Apr 28, 2000



Application Security Testing: An Integral Part of DevOps

Sorting Arrays of Primitive Types

Sorting arrays of primitive types (byte, char, double, float, int, long, and short) is easy. Example:
import java.util.*;
import java.awt.*;

class SortDBL						// Sorts an array of randomly generated double values.
	public static void main(String[] args)
		double[] dblarr = new double[10];
		for (int i=0; i < dblarr.length; i++)
		      dblarr[i] = Math.random();	// Genertate random variables

		for (int i=0; i < dblarr.length; i++ /* Imagine using i=i+1 for the
novelty but it gets optimized anyway */)
      		System.out.print(dblarr[i], " ");	// Before

		Arrays.sort(dblarr);			// Sort the array

		for (int i=0; i < dblarr.length; i++)
      		System.out.print(dblarr[i], " ");	// After
Simple isn't it?
Jeremy Chen
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date