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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:33:30+00:00 2026-05-27T13:33:30+00:00

I have a function that creates URLs for requests as follows: public String createUrl(String

  • 0

I have a function that creates URLs for requests as follows:

public String createUrl(String path, String filename) {
        return new StringBuilder(path).append("?filename=").append(filename).toString();
        }

Now, what I want to do is to add another parameter to the URL called transactionId. A naive implementation would be:

 public String createUrl(String path, String filename,String transactionId) {
            return new StringBuilder(path).append("?filename=").append(filename).append("?transactionId=").append(transactionId).toString();
            }

or I can have a static method somewhere that returns a transactionID and modify the code as follows:

 public String createUrl(String path, String filename) {
            return new StringBuilder(path).append("?filename=").append(filename).append("?transactionId=").append(TransactionMonitor.getTransactionId()).toString();
            }

Both of these approaches makes me modify the preexisting code. Is there an approach that I can take to decorate the url returned by the method with new parameters. Also, it will be great if the solution is configurable.

Thanks

  • 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-27T13:33:31+00:00Added an answer on May 27, 2026 at 1:33 pm

    You can create UrlBuilder class that builds url for you:

    class UrlBuilder {
    
        private String path;
    
        private Map<String, String> parameters = new LinkedHashMap<String, String>();
    
        public UrlBuilder path(String path) {
            this.path = path;
            return this;
        }
    
        public UrlBuilder parameter(String param, String value) {
            parameters.add(param, value);
            return this;
        }
    
    
        public String build() {
            String paramsString = "";
    
            for (Map.Entry<String, String> entry: parameters.entrySet()) {
                if (paramsString.isEmpty()) {
                    paramsString += "?";
                }
                paramsString += params.getKey() + "=" + params.getValue();
            }
    
            return path + paramsString;
        }
    
    }
    

    and use it in your code

    new UrlBuilder().path("http://google.com").params("q", "java").build()

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

Sidebar

Related Questions

Say I have a function func(i) that creates an object for an integer i,
I have the following function that takes a number like 5 and creates a
I have a win form that creates a site in IIS7. One function needs
Ok, I have one JavaScript that creates rows in a table like this: function
Modern browsers have multi-tab interface, but JavaScript function window.showModalDialog() creates a modal dialog that
When you have a function with a string parameter, does that create another instance
imagine you have a function that creates/copies/moves files. [logic] For the case that a
I have two functions, one that creates a table like so: function return_formatted_results(result_no,addy,title,own_comment) {
I have a function that processes a given vector, but may also create such
I have created a function that takes a SQL command and produces output that

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.