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

One good way to start on a task that seems too complicated is to take some simpler part of the task and write a method to accomplish just that.

You could write an arrayMax() static method to find the maximum of an ArrayList<Integer> object. Don't forget that the built-in class Math has a static method Math.max(a,b) which will return the maximum of two integer values without any if/else. You could also make your own 3-value maximum function with:

static int max3(int a, int b, int c) {
    return Math.max(a, Math.max(b, c));
}

Write and test those separately. When they work as expected you can use them as tools to get your main task done. The maximum across three lists can be found by taking the maximum of each list separately and then using that max3() method to get the maximum of those three values.

Another good start on any task that involves writing is to get the spelling and capitalization right. There is no "interger" type in any language that I'm aware of. The word is "integer" (with no r in the middle) and the Java data type you need for an ArrayList element type is "Integer". Proper spelling of reserved words and predefined types is crucial in programming. It's also a good idea in comments and user-defined names, especially for code you might want to show a prospective employer (or hand in for a class assignment.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.