This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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: 12766
51
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.
 
please buy my thing and then I'll have more money:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!