How hard is it to find a tenured position?

How to find the max value of an arraylist and two of its Index position using java?

  • Hi, Pls anybody suggest how to find the maximum value from an arraylist with its index position using java. ArrayList ar=new ArrayList; ar.add(2); ar.add(4); ar.add(12); ar.add(10); ar.add(12); String obj = Collections.max(ar); int index = ar.indexOf(obj); System.out.println("obj max value is"+obj +" and index position is"+ index); In the above program, it just returns the output as obj max value is 12 and index position is 2. But my actual output want to be as index position will be 2 and 4 (Bcoz max value 12 is present in two index position). Please suggest any ideas. Thanks in advance.

  • Answer:

    ArrayList ar=new ArrayList(); ar.add(2); ar.add(4); ar.add(12); ar.add(10); ar.add(12); int obj = Collections.max(ar); for(int index = 0; index<ar.size() ;index++){ if(ar.get(index).equals(obj)){ System.out.println("obj max value is "+ obj + " and index position is "+ index); } }

karthika R at Yahoo! Answers Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.