Question: I'm new to Java and I'm stuck at a point where I'm supposed to complete a method with a static ArrayList; I have to use a for loop. I've tried to ask several people but I simply don't understand what to do.

It looks like this (I'm supposed to complete it)

```
public static ArrayList<Message> getMessagesTo(Person recipient) {
    ArrayList<Message> allMessages = getMessages();
    return allMessages;
}

```

and so far what I've done is this

```
public static ArrayList<Message> getMessagesTo(Person recipient) {
    ArrayList<Message> allMessages = getMessages();
    for(Message message : allMessages) {
        System.out.println(message.getMessageBody());

        if(message.getRecipient().getName().equals(recipient)) {
            getMessagesTo(recipient);

    }
            return allMessages;

```

(BlueJ) then says "missing return statement" but I know that my mistake is in this part:

```
if(message.getRecipient().getName().equals(recipient)) {
                getMessagesTo(recipient);

            }

```

Answer: 
You can create one object to define order of each letter and sort by that object.

```js
var cars = ["a", "c", "r", "s"];
var s = {c: 1, a: 2, r: 3, s: 4}
var r = cars.sort((a, b) => s[a] - s[b]).join(',')

console.log(r)
```
You should implement your own custom function and pass it to the array sort function. 
Your custom function should have the criteria to order the elements in the array.

```
var cars = ["a", "c", "r", "s"];
cars.sort(function(a, b) {
   //Return the result of comparing your a and b elements.
   return result;
});
console.log(cars.join(""));

```