Check out example codes for "trier un tableau de string java". It will help you in understanding the concepts better.

Code Example 1

// How to Sort Object Array in Java using Comparator and Comparable
Course[] courses = new Course[4];
courses[0] = new Course(101, "Java", 200);
courses[1] = new Course(201, "Ruby", 300);
courses[2] = new Course(301, "Python", 400);
courses[3] = new Course(401, "Scala", 500);
       
System.out.println("Object array before sorting : " + Arrays.toString(courses));
       
Arrays.sort(courses);
System.out.println("Object array after sorting in natural order : " + Arrays.toString(courses));
       
Arrays.sort(courses, new Course.PriceComparator());
System.out.println("Object array after sorting by price : " + Arrays.toString(courses));
       
Arrays.sort(courses, new Course.NameComparator());
System.out.println("Object array after sorting by name : " + Arrays.toString(courses));

Code Example 2

int compare(T o1,
          T o2)
 
Retourne un entier négatif (<0), zéro ou un entier positif (>0) si le premier argument est plus petit, égale à ou plus grand que le deuxième argument.

Code Example 3

import java.util.Arrays;

// creating an array with integers
int[] array = {7, 4, 2, 1, 19};
// this is the sorting part just one function ready to be used
Arrays.sort(array);
// prints [1, 2, 4, 7, 19]
System.out.println(Arrays.toString(array));

Code Example 4

Arrays.sort(names, 0, names.length, Collections.reverseOrder());
System.out.println("String array after sorting in descending order : " + Arrays.toString(names));

Code Example 5

String[] names = {"John", "Steve", "Shane", "Adam", "Ben"};
System.out.println("String array before sorting : " + Arrays.toString(names));
Arrays.sort(names); 
System.out.println("String array after sorting in ascending order : " + Arrays.toString(names));

Code Example 6

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
  
class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        final String[] data = new String[] {"Raaata", "Tatatara", "Ratatouille", "Gygyghhhygra", 
            "Rasatouille", "Paratouille", "Parasouille", "Bla", "Toto"};
        Arrays.sort(data, new Comparator<String>() {
            @Override
            public int compare(String s1, String s2) {
                int idx1 = s1.toLowerCase().indexOf("ra");
                int idx2 = s2.toLowerCase().indexOf("ra");
                if(idx1 == -1 || idx2 == -1) {
                    if(idx1 == -1) {
                        idx1 = Integer.MAX_VALUE;
                    }
                    if(idx2 == -1) {
                        idx2 = Integer.MAX_VALUE;
                    }
                } else if(idx1 == idx2) {
                    return s1.substring(idx1).compareTo(s2.substring(idx2));
                }
                 
                Integer i1 = new Integer(idx1);
                Integer i2 = new Integer(idx2);
                return i1.compareTo(i2);
            }
        });
        System.out.println("Sorted array=" + Arrays.toString(data));
    }
}

Code Example 7

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
 
class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        final String[] data = new String[] {"Raaata", "Tatatara", "Ratatouille", "Gygyghhhygra", "Bla", "Toto"};
        Arrays.sort(data, new Comparator<String>() {
            public int compare(String s1, String s2) {
                int idx1 = s1.toLowerCase().indexOf("ra");
                int idx2 = s2.toLowerCase().indexOf("ra");
                if(idx1 == -1) {
                    idx1 = Integer.MAX_VALUE;
                }
                if(idx2 == -1) {
                    idx2 = Integer.MAX_VALUE;
                }
                Integer i1 = new Integer(idx1);
                Integer i2 = new Integer(idx2);
                return i1.compareTo(i2);
            }
        });
        System.out.println("Sorted array=" + Arrays.toString(data));
    }
}

Learn ReactJs, React Native from akashmittal.com