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
Related Q & A:
- How to upload file to google cloud storage using Java?Best solution by Stack Overflow
- How to Implement Gateway Service something similar to Oracle API gateway Using Java and Java based Open Source frameworks only?Best solution by Quora
- how can I listen for database changes using java?Best solution by Stack Overflow
- How to find the index of value in python list?Best solution by Stack Overflow
- How would I find the present value of a short position zero coupon bond?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.