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
Wardrobe engineering is important because
levacccp [35]

Answer:

The answer is "Option d"

Explanation:

The wardrobe engineering consists of choosing clothes that are so simple in design and better in the style that they are acceptable to the existing show-up and perfect for the future years. This design Originally coined Dressing for Confidence author John Molloy, which describe that clothes and accessories can also be used to create a certain picture, and wrong choices can be described as follows:

  • In option a, It's right, that we know about current fashions, but selecting suitable career apparel is not important, that's why it is incorrect.
  • In option b, It is wrong because whatever you wear is not to make choices of any sort.
  • In option c, It is wrong because it can't provide promotion.

3 0
3 years ago
A ____ is an e-mail attack in which the attacker routes large quantities of e-mail to the target system hoping to overwhelm the
GarryVolchara [31]

Answer:

Mail bomb is the correct answer.

Explanation:

In the following statement, A mail bomb is the type of attack on e-mail of the particular person by which the attacker transfers large quantities of e-mail to the target computer in the expectation of flooding the target with so much meaningless e-mail that legitimate e-mail is not accessible. So, that's why the following answer is correct.

3 0
2 years ago
What is the best way to describe how your voice should sound when you read a story out loud
umka21 [38]
Full of emotion and not like a robot 
3 0
3 years ago
How does heat affect quantum computers ?
vitfil [10]
It could overheat and break
7 0
3 years ago
When purchasing a security program, you must make sure that _____. Select 2 options.
Oliga [24]

Answer:

1 ans 3

Explanation:

3 0
2 years ago
Other questions:
  • How can I change it to accepted file types: .ppt, .pptx, .xls, .xlsx, .doc, .docx, .zip, .pdf, .accdb, .msg on Inkscape?
    15·2 answers
  • What is a good analogy for explaining the actions of a compiler?
    10·1 answer
  • n a​ poll, 6767​% of Internet users are more careful about personal information when using a public​ Wi-Fi hotspot. What is the
    11·1 answer
  • 2. The factorial of a positive integer n is the product of the integers from 1 to n. You can express the factorial of a positive
    6·1 answer
  • Czy FALL GUYS będzie działało szybko na i5 GH8? Na ilu FPS?
    13·1 answer
  • Help please what is the answer , thanks!!!
    13·1 answer
  • If a folder exists on an NTFS partition, which permission is needed by a user who needs to set security permissions on the folde
    11·1 answer
  • What is the difference between
    14·1 answer
  • What options are available for storing backups, physically?
    15·1 answer
  • after adding a sound to a slide, the audio tools tab will allow you to apply artistic effects and quick styles to your sound ico
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!