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 848873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:00:40+00:00 2026-05-15T07:00:40+00:00

I’m learning how to code in Java after after coming from C. In C

  • 0

I’m learning how to code in Java after after coming from C. In C I always separated everything into individual functions to make the code easier to follow and edit. I was trying to do this in java but now since I realized that you can’t use pointers, I am a bit confused as to what the best way to do this is.

So for example I want to have a method that creates four alerts for me. So I pass it an alert builder that can then create the alerts. I can return them in an array, but in my code I already have the alerts individually named, and I would like to keep it that way so I wouldn’t need to refer to them as alert[1], alert[2]… etc.

So that means I would have to rename them, which would add additional code which would probably be longer than the code in the actual method!

Am I thinking about this the right way? Is there anything I can do?

-Edit-

        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setMessage(this.getString(R.string.ache_Q_text))
               .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {dialog.cancel();}
               });

        final AlertDialog ache_Q_alert = builder.create();

        builder.setMessage(this.getString(R.string.food_Q_text));
        final AlertDialog food_Q_alert = builder.create();

        builder.setMessage(this.getString(R.string.event_Q_text));
        final AlertDialog event_Q_alert = builder.create();

        builder.setMessage(this.getString(R.string.ache_Q_text));
        final AlertDialog ache_type_Q_alert = builder.create();

and instead replace it with

createAlerts();

and have that code off somewhere to the side.

  • 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-05-15T07:00:41+00:00Added an answer on May 15, 2026 at 7:00 am

    It sounds like you want to have a method create four objects for you and return them. You have a few options:

    1. Modify your method to create only one object, and call it four times, e.g.

    Alert foo = createOneAlert(x,y,z);
    Alert bar = createOneAlert(a,b,c);
    // etc.
    

    2. Create a data structure to hold your alerts:

    public class Alerts {
      private final Alert foo;
      private final Alert bar;
      private final Alert baz;
      private final Alert quux;
    
      public Alerts(Alert foo, Alert bar, Alert baz, Alert quux) {
        this.foo = foo;
        this.bar = bar;
        this.baz = baz;
        this.quux = quux;
      }
    
      public Alert getFoo() { return foo; }
      // etc.
    
    }
    
    public Alerts makeAlerts(AlertBuilder builder) {
      return new Alerts(
        builder.buildAlert(a,b,c),
        builder.buildAlert(d,e,f),
        builder.buildAlert(g,h,i),
        builder.buildAlert(x,y,z));  
    }
    

    It may be more verbose but a) that’s Java and b) verbosity can be a good thing

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

Sidebar

Ask A Question

Stats

  • Questions 460k
  • Answers 460k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You may try this- (I have copied some code from… May 15, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer Basically, you will have to use animate() and css() to… May 15, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer Assuming this is an appropriately formatted date for XML, you… May 15, 2026 at 11:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.