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

  • SEARCH
  • Home
  • 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 8053467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:51:13+00:00 2026-06-05T07:51:13+00:00

I have a trivial, but irritating problem in Java. Suppose we have the following

  • 0

I have a trivial, but irritating problem in Java. Suppose we have the following class and method:

class A{
    void doSth(int[] array){    
        int index1, index2, index3;
        int value1, value2, value3;    

        if(array[index1] > 10){    
            //Long code modifies value1, value2, value3
        }  

        if(array[index3] > 100){    
            //Same long code modifies value1, value2, value3
        }      

        if(array[index2] > 20){    
            //Same long code modifies value1, value2, value3
        }    
    }

Disregarding what this is trying to achieve, I would like to somehow make this redundancies disappear. usually, I would pass the values to a hlper method, but I can’t, since the block is modifying local variables. Any idea how to simplify this?

  • 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-05T07:51:16+00:00Added an answer on June 5, 2026 at 7:51 am

    It sounds like you value1, value2 and value3 probably have some meaning in combination. So encapsulate them into a separate class, and at that point you can call a method which either modifies an existing instance or returns a new instance of that class. Either way, with a single local variable you’ll be fine.

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

Sidebar

Related Questions

I'm new and this is probably very trivial but I have the following method
It may be trivial, but I have following code that is dynamically adding some
I have what seemed at first to be a trivial problem but turned out
I have problem that seems to be rather trivial but I was not able
This may sound trivial but i have a problem with setting selected item in
I have code which is trivial but only works in IE not Firefox. $(document).ready(function(){
This seems fairly trivial but I can't seem to work it out I have
I know this is probably rather trivial but I have had a look at
This is really trivial but I'm getting an error I didn't expect. I have
I realise this is a trivial question but I don't have access to a

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.