O
O
Oleg Carp2019-10-10 20:53:59
Java
Oleg Carp, 2019-10-10 20:53:59

(Java) How to sort this array of objects?

How to sort the given List array by the id string, so that the object with id=true comes first, and after false. Or is it unrealistic?

public class Met {
    public static void main(String[] args){

        Object[] List = {
            new Student(),
            new Schoolboy()
        };

    }

    public static class Student{
       private boolean id=true;
        public boolean isId() {
            return id;
        }
    }

    public static class Schoolboy{
        private boolean id=false;
        public boolean isId() {
            return id;
        }

    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Cheypnow, 2019-10-11
@Rebel-Cat

Call Collections.sort() and pass the required comparator there

D
Dmitry Alexandrov, 2019-10-10
@jamakasi666

Read the basics, and not even java in particular.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question