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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:12:12+00:00 2026-05-16T18:12:12+00:00

I need the following functionality Given two sorted lists, merge them I have this

  • 0

I need the following functionality

Given two sorted lists, merge them

I have this skeleton Java code:

public class MergeLists{
   public List merge(List l1, List l2){
      List l3;
      // merge l1, l2 in to l3
      return l3;
   }

   public static void main(){
      // populate list1 and list2
      MergeLists ml = new MergeLists();
      List l3 = ml.merge(l1,l2);
   }
}

Is this single method class the right approach? I feel like the almost-empty class is staring at me to say that this is bad design. I initially had List L3 as private member of MergeLists but then I thought, merge(l1,l2) can be called multiple times with the same object, which required l3 to be local to merge(l1,l2).
I read that using static method is even worse for code re-usability. Please advise. Thank you.

  • 1 1 Answer
  • 3 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-16T18:12:13+00:00Added an answer on May 16, 2026 at 6:12 pm

    In this case, since you have no true member data, making the single method a static method inside the class would be the appropriate design choice:

    public class ListUtils
    {
        public static List Merge(List l1, Listl2)
        {
            List l3 = new List();
            // merge l1 and l3 into l3
            return l3;
        }
    }
    

    You can then use the code without having to create an instance of your class (especially when it serves no purpose):

    List l1 = new List();
    List l2 = new List();
    // Fill the lists
    
    List merged = ListUtils.Merge(l1, l2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public static string FormatHostAndUrl(this HttpSessionStateBase session) { var a
I need to do mimic the functionality of the following Perl code if($file =~
I'm new to WPF but I need to implement following functionality: I have a
I have a JSF (IceFaces 1.8.2) website. I need the following functionality: When a
I need the following xml to be made in code: <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:gravity=right
I need to create the following functionality, and looking for the best way to
I need some kind of advise, how to use technologies to achieve following functionality:
I need to port the functionality of this one and only one AJAX control
I have the following logic: public void InQueueTable(DataTable Table) { int incomingRows = Table.Rows.Count;
I need to provide following functionality for one of the web sites. http://www.example.com/ [sponsor]

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.