1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mamaluj [8]
3 years ago
10

Given two ArrayLists of sorted strings (alphabetically ascending), write down a method to merge these sorted strings’ ArrayLists

into a single sorted ArrayList. The signature of the method is given below: public static ArrayList mergeList(ArrayList lst1, ArrayList lst2) Write down a test method that tests the above method. As an example if: List1 has its elements: "Austin" "Dallas" "San Francisco" and List2 has its elements : "Boston" "Chicago" "Denver" "Seattle" then the merged sorted list should have the elements in the following order : "Austin" "Boston" "Chicago", "Dallas" "Denver" "San Francisco" "Seattle"
Computers and Technology
1 answer:
Elena-2011 [213]3 years ago
8 0

Answer:

see explaination

Explanation:

import java.util.ArrayList;

import java.util.Arrays;

public class Merge {

public static ArrayList<String> mergeList(ArrayList<String> lst1, ArrayList<String> lst2) {

ArrayList<String> result = new ArrayList<String>();

int i = 0, j = 0;

while (i < lst1.size() || j < lst2.size()) {

if (i < lst1.size() && (j >= lst2.size() || lst1.get(i).compareTo(lst2.get(j)) < 0)) {

result.add(lst1.get(i++));

} else {

result.add(lst2.get(j++));

}

}

return result;

}

public static void main(String[] args) {

ArrayList<String> lst1 = new ArrayList<>(Arrays.asList("Austin", "Dallas", "San Fransisco"));

ArrayList<String> lst2 = new ArrayList<>(Arrays.asList("Boston", "Chicago", "Denver", "Seattle"));

System.out.println(mergeList(lst1, lst2));

}

}

You might be interested in
A Web site that allows users to enter text, such as a comment or a name, and then stores it and later display it to other users,
balandron [24]

Answer:

Option(c) is the correct answer.

Explanation:

Cross-site scripting is the type of security breach that are usually found in the  software applications.The main objective of cross site scripting it is used by the hackers to exploit the data security.

  • The cross site scripting is the collection of web pages  that enables people to insert the text like comment,  name stores it afterwards it save the data and then  it appears to the other users.
  • Others options are incorrect because they are not related to given scenario.
5 0
2 years ago
Read 2 more answers
The faster alcohol is consumed, the faster it reaches the __________.
Anni [7]
The faster it reaches the bloodstream

6 0
3 years ago
Read 2 more answers
The number 84 is divisible by 2,3,4 and 6. true or false
Eva8 [605]
84÷2=42. 84÷3=28. 84÷4=21. 84÷6=14. So your answer is true.
8 0
3 years ago
Read 2 more answers
Savings accounts _____.
klemol [59]
???????????????????????
7 0
3 years ago
Write a program that removes all spaces from the given input.
sasho [114]

Explanation:

#include<iostream>

#include<string.h>

using namespace std;

char *removestring(char str[80])

{

   int i,j,len;

   len = strlen(str);

   for( i = 0; i < len; i++)

   {

       if (str[i] == ' ')

       {

           for (j = i; j < len; j++)

               str[j] = str[j+1];

           len--;

       }

   }

   return str;

}

int main ()

{  

char  str[80];

   cout << "Enter a string : ";

   cin.getline(str, 80);

   strcpy(removestring(str), str);

   cout << "Resultant string : " << str;

   return 0;

}

In this program the input is obtained as an character array using getline(). Then it is passed to the user-defined function, then each character is analyzed and if space is found, then it is not copied.

C++ does not allow to return character array. So Character pointer is returned and the content is copied to the character array using "strcpy()". This is a built in function to copy pointer to array.

5 0
3 years ago
Other questions:
  • Adjusting the ______ adjusts the difference in appearance between light and dark areas of the photo.​
    10·2 answers
  • The smallest building block of a wireless lan is a ______.
    5·1 answer
  • What type of engineer works on cleaning up oil spills?
    8·2 answers
  • Design a circuit that has a 3-bit binary input B2, B1, B0 (where B2 is most significant bit and B0 is least significant bit) and
    14·1 answer
  • 1) Prompt the user to enter two words and a number, storing each into separate variables. Then, output those three values on a s
    11·1 answer
  • Riya wants to save her project work in an external device so that she can show it to her class teacher. Help her to choose the d
    13·2 answers
  • Which is not one of the four criteria for proving the correctness of a logical pretest loop construct of the form: while B do S
    14·1 answer
  • During her presentation, Marie wanted more freedom to move about the room and interact with her audience. She can use _____.
    10·1 answer
  • Kayla wants to know whether she should set her network up as a WAN or a LAN. What are the three questions you would ask her, and
    11·1 answer
  • Your friend has a great idea for a new app, and she shows you a document that outlines what the app will do. This document is an
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!