Example usage for java.util Arrays sort

List of usage examples for java.util Arrays sort

Introduction

In this page you can find the example usage for java.util Arrays sort.

Prototype

public static void sort(Object[] a) 

Source Link

Document

Sorts the specified array of objects into ascending order, according to the Comparable natural ordering of its elements.

Usage

From source file:Person.java

public static void main(String[] args) {
    Person[] authors = { new Person("A", "B"), new Person("C", "D"), new Person("E", "F"), new Person("Z", "Y"),
            new Person("X", "T"), new Person("O", "R") };
    Arrays.sort(authors);
    System.out.println("\nThe cast is ascending sequence is:\n");
    for (Person person : authors) {
        System.out.println(person);
    }/*  w w w  .  jav  a2 s . c om*/
}

From source file:AverageCost.java

public static void main(String[] args) throws FileNotFoundException, IOException {
    //Directory of the n files
    String directory_path = "/home/gauss/rgrunitzki/Dropbox/Profissional/UFRGS/Doutorado/Artigo TRI15/SF Experiments/IQ-Learning/";
    BufferedReader reader = null;
    //Line to analyse
    String line = "";
    String csvDivisor = ";";
    int totalLines = 1002;
    int totalRows = 532;

    String filesToRead[] = new File(directory_path).list();
    Arrays.sort(filesToRead);
    System.out.println(filesToRead.length);

    List<List<DescriptiveStatistics>> summary = new ArrayList<>();

    for (int i = 0; i <= totalLines; i++) {
        summary.add(new ArrayList<DescriptiveStatistics>());
        for (int j = 0; j <= totalRows; j++) {
            summary.get(i).add(new DescriptiveStatistics());
        }//from  ww  w.j  a v a  2 s  .  c  o m
    }

    //reads all files
    for (String file : filesToRead) {
        reader = new BufferedReader(new FileReader(directory_path + file));
        int lineCounter = 0;
        //reads all file's line
        while ((line = reader.readLine()) != null) {
            if (lineCounter > 0) {
                String[] rows = line.trim().split(csvDivisor);
                //reads all line's row
                for (int r = 0; r < rows.length; r++) {
                    summary.get(lineCounter).get(r).addValue(Double.parseDouble(rows[r]));
                }
            }
            lineCounter++;
        }

        //System.out.println(file.split("/")[file.split("/").length - 1] + csvDivisor + arithmeticMean(avgCost) + csvDivisor + standardDeviation(avgCost));
    }

    //generate mean and standard deviation;
    for (List<DescriptiveStatistics> summaryLines : summary) {
        System.out.println();
        for (DescriptiveStatistics summaryLineRow : summaryLines) {
            System.out.print(summaryLineRow.getMean() + ";" + summaryLineRow.getStandardDeviation() + ";");
        }
    }
}

From source file:Main.java

  public static void main(String[] args) {
  double doubleArray[] = { 1.3, 2.1, 4.7, 5.3 };
  Arrays.sort(doubleArray);

  double searchValue = 4.7;

  System.out.println(Arrays.binarySearch(doubleArray, searchValue));

  searchValue = 3.33;// w  w w . ja  v  a 2 s . c  o  m
  System.out.println(Arrays.binarySearch(doubleArray, searchValue));
}

From source file:EmployeeSortTest.java

public static void main(String[] args) {
    Employee[] staff = new Employee[3];

    staff[0] = new Employee("Harry Hacker", 35000);
    staff[1] = new Employee("Carl Cracker", 75000);
    staff[2] = new Employee("Tony Tester", 38000);

    Arrays.sort(staff);

    // print out information about all Employee objects
    for (Employee e : staff)
        System.out.println("name=" + e.getName() + ",salary=" + e.getSalary());
}

From source file:com.chevrier.legiondao.boot.Boot.java

public static void main(String[] args) {
    //SpringApplication.run(Boot.class);

    SpringApplication app = new SpringApplication(ConfigJpa.class);
    //app.setLogStartupInfo(false);
    // on la lance
    ConfigurableApplicationContext context = app.run(args);

    PersonnageRepository personnageRepository = context.getBean(PersonnageRepository.class);

    Iterable<Personnage> allPersonnage = personnageRepository.findAll();

    allPersonnage.forEach(perso -> log.info(perso.getNom()));
    System.out.println("Let's inspect the beans provided by Spring Boot:");

    String[] beanNames = context.getBeanDefinitionNames();
    Arrays.sort(beanNames);
    for (String beanName : beanNames) {
        System.out.println(beanName);
    }/*from w  ww .  jav a2s.com*/
    // fermeture du contexte Spring
    context.close();
}

From source file:com.rationaldevelopers.oss.Application.java

public static void main(String[] args) {
    ApplicationContext ctx = SpringApplication.run(Application.class, args);
    ctx.getBean(QueueService.class);

    log.info("Let's inspect the beans provided by Spring Boot:");
    String[] beanNames = ctx.getBeanDefinitionNames();
    Arrays.sort(beanNames);
    for (String beanName : beanNames) {
        log.info("=======> {}", beanName);
    }/*from   w w  w  . java 2 s. c  o  m*/

}

From source file:de.kaiserpfalzEdv.iam.tenant.service.ApplicationStart.java

public static void main(String[] args) {
    ApplicationContext ctx = SpringApplication.run(ApplicationStart.class, args);

    LOG.info("Let's inspect the beans provided by Spring Boot:");

    String[] beanNames = ctx.getBeanDefinitionNames();
    Arrays.sort(beanNames);
    for (String beanName : beanNames) {
        LOG.info("  Bean: {}", beanName);
    }// w  ww. j a  v a 2s  .c  o m
}

From source file:Main.java

  public static void main(String[] args) {
  float floatArray[] = { 1.2f, 2.1f, 4.7f, 5.3f };
  Arrays.sort(floatArray);

  float searchValue = 4.7f;
  System.out.println(Arrays.binarySearch(floatArray, searchValue));

  searchValue = 3.3f;//from   w ww .  j a v a 2  s.  c  om
  System.out.println(Arrays.binarySearch(floatArray, searchValue));
}

From source file:org.project.ExampleApplication.java

public static void main(String[] args) throws Exception {
    ApplicationContext ctx = SpringApplication.run(ExampleApplication.class, args);

    // Showing all the beans mapped
    String[] beanNames = ctx.getBeanDefinitionNames();
    Arrays.sort(beanNames);
    for (String beanName : beanNames) {
        System.out.println(beanName);
    }/*from w w w.  j av  a 2 s.  c om*/

    Bootstrap bootstrap = (Bootstrap) ctx.getBean("bootstrap");
    bootstrap.setup();

}

From source file:ArraysTester.java

public static void main(String[] args) {
    ArraysTester tester = new ArraysTester(50);
    int[] myArray = tester.get();

    // Compare two arrays
    int[] myOtherArray = tester.get().clone();
    if (Arrays.equals(myArray, myOtherArray)) {
        System.out.println("The two arrays are equal!");
    } else {/*from  w  w  w  .j  a  v  a 2  s. co m*/
        System.out.println("The two arrays are not equal!");
    }

    // Fill up some values
    Arrays.fill(myOtherArray, 2, 10, new Double(Math.PI).intValue());
    myArray[30] = 98;

    // Print array, as is
    System.out.println("Here's the unsorted array...");
    System.out.println(Arrays.toString(myArray));
    System.out.println();

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

    // print array, sorted
    System.out.println("Here's the sorted array...");
    System.out.println(Arrays.toString(myArray));
    System.out.println();

    // Get the index of a particular value
    int index = Arrays.binarySearch(myArray, 98);
    System.out.println("98 is located in the array at index " + index);

    String[][] ticTacToe = { { "X", "O", "O" }, { "O", "X", "X" }, { "X", "O", "X" } };
    System.out.println(Arrays.deepToString(ticTacToe));

    String[][] ticTacToe2 = { { "O", "O", "X" }, { "O", "X", "X" }, { "X", "O", "X" } };

    String[][] ticTacToe3 = { { "X", "O", "O" }, { "O", "X", "X" }, { "X", "O", "X" } };

    if (Arrays.deepEquals(ticTacToe, ticTacToe2)) {
        System.out.println("Boards 1 and 2 are equal.");
    } else {
        System.out.println("Boards 1 and 2 are not equal.");
    }

    if (Arrays.deepEquals(ticTacToe, ticTacToe3)) {
        System.out.println("Boards 1 and 3 are equal.");
    } else {
        System.out.println("Boards 1 and 3 are not equal.");
    }
}