Sort an arraylist of an arraylist of doubles

558fe5180e0e8fc922d31c23ef84d240

I am looking to sort an arraylist of arraylist of doubles and I require help?

I was informed that I need to implement comparator or comparable and then use the collection.sort to sort the list of list in order...

ArrayList<ArrayList> list = new ArrayList<ArrayList>()

If you look at the list of list as the following example:

c1-5.0,4.5,10.3,3.5

c2-2.5,1.0,7.8,8.6

c3-6.0,5.6,9.6,9.5

It show go to this

c1-2.5,1.0,7.8,3.5

c2-5.0,4.5,7.8,8.6

c3-6.0,5.6,10.3,9.5

Find the smallest, largest and medium number by comparing 3 array list

558fe5180e0e8fc922d31c23ef84d240

How do I compare 3 Arraylist with each other and find the small, medium and large elements. I was thinking something like this but its not working.

ArrayList<interger> a = new ArrayList<ArrayList<interger> >(); 
a.add(1);
a.add(2);
a.add(7);
ArrayList<interger> b =new ArrayList<ArrayList<interger> >();
b.add(8);
b.add(9);
b.add(1);
ArrayList<interger> c = new ArrayList<ArrayList<interger> >();
c.add(5);
c.add(9)
c.add(8)

 for (int i = 0; i < ; i++) 
        {
            for (int j = 0; j < ; j++) 
            {
                for (int k = 0; k < ; k++) 
                {

        if () {}

        if () {}    

        if () {}
         }
      }}

output:
small =1,2,1
medium = 5,9,7
large = 8,9,8

Calculating distance with arraylist

558fe5180e0e8fc922d31c23ef84d240

I would like to calculate the distance in 4d I have 2 arraylist that have all of my elements in it. How do make the formula i have this but its not calculating correctly the distance. List has diferent coordinates every time and t always has the same coordinates.

        double w = 0.0;

        for (int i = 0; i < List.size(); i++)
        {
            for (int j = 0; j < List.get(i).size(); j++)
          {
           w =   Math.sqrt(Math.pow(List.get(i).get(j) - t.get(j), 2)+Math.pow(List.get(i).get(j) - t.get(j), 2)+Math.pow(List.get(i).get(j) - t.get(j), 2)+Math.pow(List.get(i).get(j) - t.get(j), 2));
          }
        System.out.println(w);

Divide arraylist of 750 into 150 sub arraylist

558fe5180e0e8fc922d31c23ef84d240

I have an ArrayList of 750 elements I would like to divide that ArrayList into 150 subarraylists so 5 elements to each subarraylist.

I have this code but it not working

while (scanner.hasNextLine()) {
            String t = scanner.nextLine();
            String[] ar = t.split(",");

            for (int i = 0; i < ar.length; i++) 
            {
                add.add(Double.parseDouble(ar[i]));
            }

Select every 5 numbers random

558fe5180e0e8fc922d31c23ef84d240

I have an array list that looks like this.

8.1,6.5,4.4,3.2,1,8.9,5,1.4,0.1,1,8.7,6.2,4.3,3.2,3

I would like that my program selects every 5 numbers randomly.

for example to select

8.1,6.5,4.4,3.2,1,8.7,6.2,4.3,3.2,3

as you can see it selected 5 numbers from the begging and 5 more from the end

and saves them

Random random_method = new Random();

// loop for generation random number
for (int i = 0; i < array.size(); i++)

// generating random index with the help of
// nextInt() method
int index = random_method.nextInt(array.size());

System.out.println("Random Element is :" + array.get(index));