---
title: "Most efficient way to simultaneously sort three ArrayLists in Java"  
description: "Most efficient way to simultaneously sort three ArrayLists in Java"  
author: "Anonymous User"  
published: 2015-12-15  
updated: 2015-12-15  
canonical: https://www.mindstick.com/forum/33734/most-efficient-way-to-simultaneously-sort-three-arraylists-in-java  
category: "java"  
tags: ["java", "array list", "sorting"]  
reading_time: 2 minutes  

---

# Most efficient way to simultaneously sort three ArrayLists in Java

I am three ArrayLists. One of [Strings](https://www.mindstick.com/forum/161912/explain-the-python-strings) - names, and two of Integers - [score](https://www.mindstick.com/articles/126373/world-cup-2019-live-score) and [picture](https://answers.mindstick.com/qa/38554/name-the-oscar-winning-sound-designer-who-became-the-first-asian-to-win-the-award-for-best-sound-for-documentary-india-s-daughter-at-the-coveted-motion-picture-sound-editors-63rd-annual-golden-reel-awards) numbers. I want to sort them simultaneously by the [players](https://www.mindstick.com/articles/12952/the-8-major-mistakes-players-make-in-the-casinos) scores (from highest to lowest). [Now](https://yourviews.mindstick.com/view/81402/it-s-liberals-vs-progressives-in-us-politics-now) i use a [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) [bubble sort](https://www.mindstick.com/forum/157933/write-a-program-to-sort-an-array-of-integers-using-the-bubble-sort-algorithm), but i think it will not be [efficient](https://www.mindstick.com/articles/33637/three-tips-for-an-energy-efficient-home-for-2019) when the [Lists](https://www.mindstick.com/articles/126273/books-commonly-found-on-college-reading-lists) will be bigger.\
My [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
public class MyBubbleSort {    public static void bubble_srt(List<Integer> score, List<String> name, List<Integer> pic) {        int n = score.size();        int k;        for (int m = n; m >= 0; m--) {            for (int i = 0; i < n - 1; i++) {                k = i + 1;                if (score.get(i) < score.get(k)) {                    swapNumbers(i, k, score, name, pic);                }            }            printNumbers(score);        }    }    private static void swapNumbers(int i, int j, List<Integer> score, List<String> name, List<Integer> pic) {        int temp;        temp = score.get(i);        score.set(i, score.get(j));        score.set(j, temp);        String s;        s = name.get(i);        name.set(i, name.get(j));        name.set(j, s);        int p;        p = pic.get(i);        pic.set(i, pic.get(j));        pic.set(j, p);    }    private static void printNumbers(List<Integer> input) {        for (int i = 0; i < input.size(); i++) {            System.out.print(input.get(i) + ", ");        }        System.out.print("\n");    }}
```

## Replies

### Reply by Anonymous User

Best way would be to create a class containing score, name and pic properties and have a single List of that class, which you sort using Collections.sort and a Comparator that compares two instances of your class according to the score property.\
Bubble sort is in-efficient compared to other sorting algorithms (merge sort, quick sort), and there's no need to implement a sort algorithm yourself, since the standard Java packages already do that for you.


---

Original Source: https://www.mindstick.com/forum/33734/most-efficient-way-to-simultaneously-sort-three-arraylists-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
