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]
4 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]4 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
Identify the final stage of the object found in the image in the given text
timama [110]

Answer:

science fiction book

Explanation:

3 0
3 years ago
Convert each of the following bit patterns into whole numbers. Assume the values are stored
Rus_ich [418]

Answer:

1. 45

2. 90

3. 161

4. 227

Explanation:

Binary starts off with the first bit equaling 1 and then each subsequent bit being double the previous bit from right to left, so.

128, 64, 32, 16, 8, 4, 2, 1 In this example. If you imagine each 1 or 0 being and on or off for the value it's related to, you just add the numbers together that are on (with a 1 on them)

7 0
3 years ago
In powerpoint a point is _____ of an inch in height.
USPshnik [31]
 a fraction

I think it is correct.

Hopefully it helps.
6 0
3 years ago
Which of the following inputs help robotic vacuum cleaners maneuver around obstacles?
Alja [10]

Answer:

c lasers and sensors

Explanation:

7 0
3 years ago
Read 2 more answers
How to give answer like this?????
creativ13 [48]

Answer:

possibly he made an image in the photo or this

Explanation:

\large\boxed{\mathfrak{hi}}

8 0
3 years ago
Other questions:
  • The smallest unit of time in music called?
    6·2 answers
  • In a microsoft word document, what is the amount of space that appears between paragraphs called?
    14·1 answer
  • What are computers used for?
    14·2 answers
  • The assignment of numeric codes to characters follows a specific order called a(n) _____.
    15·1 answer
  • For businesses and organizations under recent compliance laws, data classification standards typically include private, confiden
    11·1 answer
  • Using a single formatting _______ helps to make reading researched information easier; it lets the reader know what to expect.
    7·1 answer
  • What does the gym member need to give?​
    8·1 answer
  • In order to convert your project to a mobile platform, you need to do all of the following except:
    14·1 answer
  • Use the factorial operation to evaluate 4!.<br><br> 24<br><br> 1<br><br> 4<br><br> 10
    10·1 answer
  • A flowchart meeting is a process where members of the team analyze the design piece-by-piece to make sure it meets requirements
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!