answersLogoWhite

0

Here's simple example to sort numbers in Java using a List:

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

public class SortTest {

public static void main (String[] args) {

List<Integer> list = new ArrayList<Integer>();

list.add(100);

list.add(1);

list.add(24);

list.add(3);

System.out.println(list);

Collections.sort(list);

System.out.println(list);

}

}

Running it generates the following output:

[100, 1, 24, 3]

[1, 3, 24, 100]

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What Program that will display the even numbers in data structures and algorithms?

JAVA


Write a java program to sort a list of numbers?

The simplest would be to put the numbers into an int[] (integer array) and pass that to java.util.Arrays.sort(int[]) (a static method), which will sort the array in ascending numerical order. Use a float[] or double[] if you need to sort non-whole numbers. You can also use the Collections.sort(List) method to sort the List directly. Or the Collections.sort(List, Comparator) if you wish to specify your own sorting criteria.


How do you compile and execute a java program which finds out the highest of any five numbers?

it will be destroyed.


What do you mean by multithread program in java?

A Program in Java that spawns multiple threads is called a multithreaded program in Java.


What does it mean to generate random numbers in Java?

Generating random numbers in Java is somewhat of a misnomer because the numbers are actually semi-random.It means to use the program to obtain random integers to use in hypothetical situations such as statistics.


Java program to find sum on even numbers from 12-45?

sum = 0; for (int i = 12; i


What is java program on computers?

#!/usr/bin/perl print 'java program';


What is java virtucal mechine?

That refers to the program that runs the compiled Java program.


What is the Java program for sorting an array?

Java has a very efficient built in implementation of quick sort. You can use it on any array of primitives or Comparable Objects by invoking Arrays.sort(&lt;array&gt;) See related link.


What powder game doesnt need java?

Any program written for the Java technology needs Java. Any program NOT written for Java DOESN'T need it.


Java Track?

Java Track is the java training program offered by SynergisticIT


Where can one get the program Java?

The program Java can be downloaded from the official Java website on the internet. The program is free for personal use, so it can be downloaded without any cost by anyone.