Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:57:32+00:00 2026-06-15T22:57:32+00:00

I need a final review and some tips about a function I wrote. public

  • 0

I need a final review and some tips about a function I wrote.

  public static Integer max(Integer... pNumber) {
    Integer lResult = null;
    for (Integer lNumber : pNumber) {
      if (lResult == null || (null != lNumber && lNumber > lResult)) {
        lResult = lNumber;
      }
    }
    return lResult;
  }

I am not realy sure if my code is elegant.
null parameters as well as a null result is possible.
However… I have the feeling that I solved something in the code to complicated.
The function is part of an utility class which is used by the company.
using third party librarys is not allowed.

Here the corresponding test:

@Test
public void testMaxWithInteger() {
  assertEquals(new Integer(9), NumberUtils.max(4, 2, -4, null, 9, 5));    
}

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:57:33+00:00Added an answer on June 15, 2026 at 10:57 pm

    IMHO I wouldn’t use null objects as Integer[] can use 6x as much memory as using int[]

    public static Integer max(Integer... ints) {
        long ret = Long.MIN_VALUE;
        for (Integer i: ints) 
          if (null != i && i > ret) 
            ret = i;
        return ret >= Integer.MIN_VALUE? (int) ret : null;
    }
    

    Instead of Integer[] I would use int[] and leave 0 or Integer.MIN_VALUE as my “un-initialised” value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need mock some class with final method using mockito. I have wrote something
Do we really need static final constants in Java? Assume I have the following
I'm doing some reading and need some clarification on final classes and methods. My
I need to get the final URL after redirection in python. What's a good
I need to identify basic gestures which are performed in surface application? My final
I am doing an undergrad final project, and need to justify my choice of
I have 2 weeks to finish my final year project.I need a GUI IDE
I have just completed an application for my final year project and I need
Need a map reduce function by mongo in php This my mongo structure [_id]
Need some regular expressions help. So far I have my code working to allow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.