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
Please help me and solution in c language​
salantis [7]
Ummmm the solution is ummm brb
3 0
3 years ago
Which statement best describes the difference between a spreadsheet and a database?
Dmitrij [34]

Answer:

Databases store data in tables that interact; spreadsheets store data in cells that interact.

Explanation:

3 0
2 years ago
Read 2 more answers
#Write a function called is_composite. is_composite should #take as input one integer. It should return True if the #integer is
malfutka [58]

Answer:

// A optimized school method based C++ program to check  

// if a number is composite.  

#include <bits/stdc++.h>  

using namespace std;  

bool isComposite(int n)  

{  

// Corner cases  

if (n <= 1) return false;  

if (n <= 3) return false;  

// This is checked so that we can skip  

// middle five numbers in below loop  

if (n%2 == 0 || n%3 == 0) return true;  

for (int i=5; i*i<=n; i=i+6)  

 if (n%i == 0 || n%(i+2) == 0)  

 return true;  

return false;  

}  

// Driver Program to test above function  

int main()  

{  

isComposite(11)? cout << " true\n": cout << " false\n";  

isComposite(15)? cout << " true\n": cout << " false\n";  

return 0;  

}

Explanation:

3 0
3 years ago
A startup is developing a new web browser with a focus on accessibility for visually impaired users. The startup founder is cons
gavmur [86]

Answer:

A license that allows developers to change and share the source

code of the licensed software

Explanation:

i learned this, btw brainly stop removing my answers

7 0
2 years ago
What are the importance of switches in our electron device
svp [43]

This way we can turn it on or off so we don't waste power.

Hope I helped! Just tell me if i'm wrong!

3 0
3 years ago
Other questions:
  • Consider a relation representing the present position of molecules in a closed container. The attributes are the ID for the mole
    12·1 answer
  • Create a function generateString(char, val) that returns a string with val number of char characters concatenated together. For
    11·2 answers
  • Markaplier nand jackceptieye are the best YT ever who agrees
    5·2 answers
  • Which of the following is an accurate statement? When the LOWER function is used in a SELECT clause, it will automatically store
    6·1 answer
  • How to get the absolute value in coding begginners?
    13·2 answers
  • Write an expression to print each price in stock_prices. Sample output with inputs: 34.62 76.30 85.05
    9·1 answer
  • How do you change the top and bottom margins of an entire document?
    7·2 answers
  • Suppose you are on a desert island and possess exactly 20 coconuts your neighbor Friday is a fisherman and he is willing to trad
    14·1 answer
  • In a networking context, "architecture" refers to
    5·1 answer
  • NEED HELP ASAP
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!