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
The template for organizing SRS given by American Department ofDefense and NASA should be used for
Grace [21]

Answer: C) Medium size projects

Explanation:

 The template for organize SRS is given by the American Department of Defense and NASA should be used for medium size projects. As, SRS is the key component of the marshall center and NASA provides its space surveillance requirement to the U.S. Basically, NASA is stands for the national aeronautics and space administration and it is a independent agency for united states.

5 0
3 years ago
What kind of loop should be used in a game where the user is guessing a secret code and the message"guess again" appears until t
GenaCL600 [577]

Answer:

While loop

Explanation:

It should be noted that the number of times which the computer will ask the user to take a guess is not known.

When we have a condition like this, the while loop (or in some programs; the do-while loop) is to be used.

To further back my point, see the following program in python.

<em>secret_code = 1234</em>

<em>user_guess = int(input("Take a guess: "))</em>

<em>while user_guess != secret_code:</em>

<em>     user_guess = int(input("guess again: "))</em>

<em>print("You guessed right")</em>

<em />

The above program will keep asking the user to take a guess until the user enters 1234.

<em>This may or may not be possible with a for loop.</em>

3 0
3 years ago
_______ codes are supplemental codes used to help researchers collect data, track illness and disease, and measure quality of ca
Gnom [1K]

Answer:

Category II

Explanation:

5 0
2 years ago
Read 2 more answers
Including the direct and indirect costs, alcohol related collisions cost society _____billion dollars annually.
Anvisha [2.4K]

Answer:

C.106.

Explanation:

8 0
3 years ago
Josh has finished scanning a network and has discovered multiple vulnerable services. He knows that several of these usually hav
tankabanditka [31]

For this particular attempt, the last stage of the cyber kill chain that Josh performed is: Weaponize.

A cyber kill chain is also referred to as a cyber-attack chain and it can be defined as a series of steps that comprises the stages of a cyber attack. Thus, a cyber kill chain can be used to understand, trace and stop the sequence of events involved in a cyber attack.

Generally, a cyber kill chain comprises seven (7) main stages and these include:

1. Reconnaissance

2. Weaponize

3. Delivery

4. Exploit

5. Install

6. Callback

7. Persist

Weaponize simply involves choosing one or more attack vectors to begin an intrusion into a network system, after gathering sufficient information about the target.

In this scenario, the last stage of the cyber kill chain that Josh performed is weaponize because he decided to investigate other methods of intruding into the system, so as to send his file.

Read more: brainly.com/question/24112967

7 0
2 years ago
Other questions:
  • A simple algorithm for handling requests works like this:________ a) all requests users make are stored. b) The elevator priorit
    15·2 answers
  • In your own words, explain at least one reason why programming languages have functions.
    13·1 answer
  • On Brainly, how can I change my username? from halfsidepancake​
    6·2 answers
  • Fill in the blanks. The ________________ donut chart shows the distribution across your website’s pages by the number of clicks
    14·1 answer
  • True or false? LearnSmart (the "smart flash card assignments") really gets your competitive spirit in gear by allowing you to se
    8·1 answer
  • Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less
    6·2 answers
  • The IP address and the port are both numbers. Which statement is true?
    14·1 answer
  • Anybody know this question??
    8·1 answer
  • How do I delete my brainly account?<br> I don't need anymore.
    13·2 answers
  • Chang investigates ways to improve the interactivity of computer hardware. His job title is best described as ✓ Computer and Inf
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!