Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

min max array list

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all, sorry to bother you with this but i'm trying to find the smallest/largest int in an abstract data type list. what's the proper way to write min/max test - i see so many different ways online.
What I'm thinking is:


int smallest = Integer.MIN_VALUE;
int largest = Integer.MAX_VALUE;

}
if (x < y)
{

System.out.println("Smallest");

your insight is much appreciated.

- eddie
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post a SSCCE or may be the code which you have been trying for the same.
One way is to iterate through the list and find out the maximum and minimum elements.
 
eddie pa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, thanks for your reply, the code is very long and complicated. i guess my question should be, how to write a min max code in java? i'm new to java so i'm not sure if there is a standard way to get min max value?
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can focus on solving the min-max problem, so the way to go would be to write a sample program to solve that problem and then integrate with your large problem.
you can explore the List, Collection api. you can create a List of the elements and then sort it. If you sort it in descending order than you can pick the first element for max and the last element for min.
 
lowercase baba
Posts: 12856
52
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And before you write a single line of java code, figure out how YOU would do it, if all you had was a pencil, paper, and a VERY short term memory.
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic