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
An expression which combines variables numbers and at least one operation
hichkok12 [17]

Answer:

An "Algebraic expression" is the correct answer for the above question.

Explanation:

  • The algebraic expression is an expression that is written in the form of alphabets and numbers. For example x+2x.
  • And it is also calculated with the consideration of alphabets like X+2X will be 3X.
  • The above question asked about the expression which is used with the combination of alphabets or variables and the numbers. That expression is known as "Algebraic expression"
4 0
3 years ago
An example of what you can post that shows kindness to other
harina [27]

Answer:

everybody is awesome

Explanation:

5 0
3 years ago
What are the benefits of writing functions that use parameters and return List 2 please and explain what is return
Ratling [72]

<u>Answer and explanation:</u>

There are many benefits of writing functions that use parameters and return. Some of them are:

1. Flexibility: With functions having parameters, several values of the parameters can be used at invocation time thereby making the application flexible. For example, given the following function in Java.

<em>public void showName(String name){</em>

<em>    System.out.println("Your name is " + name);</em>

<em>}</em>

To call this method (function), the programmer could use various values for the name parameter used in the function like so:

showName("John");

showName("Doe");

If the function didn't have a parameter, it is possible it will only print a hardcoded name every time the function is called.

2. Scope Control: When a function is allowed to return a value, it helps to work around scope issues since variables declared within a function are limited to that function and do not exist outside the function. This means that the values of these variables cannot be used anywhere else outside the function in which they are being declared. However, if the function returns a value, the value can be used anywhere else in the program.

For example:

<em>public String getDouble(int x){</em>

<em>    int y = x * 2</em>

<em>    return y;</em>

<em>}</em>

The function above returns twice the value of the argument supplied to it. Since the integer variable y is declared within the function, it's value cannot be used outside the function. However, since the value is being returned by the function, it could be used anywhere the function is being called. Thanks to the return keyword.

3 0
3 years ago
A reflective cross-site scripting attack (like the one in this lab) is a __________ attack in which all input shows output on th
Murrr4er [49]

Answer:

" Non-persistent" is the right response.

Explanation:

  • A cross-site category of screenplay whereby harmful material would have to include a transaction to have been transmitted to that same web application or user's device is a Non-persistent attack.
  • Developers can upload profiles with publicly available information via social media platforms or virtual communication or interaction.
6 0
3 years ago
Prompt
madam [21]

Have you ever tried to learn a new language or do you have friends who've had that experience?

Yes, I tried to learn Python and I even managed to do two Discord bots which are (somewhat) functional, but I'm far to say that I've managed to lean the language completly. There are lots of things to learn on a language as Python.

I also leant PHP on my own and managed to do a website (somehow) functional.

What are some of the  steps you would take to learn a new language, and what are some challenges that might arise?

The first steps in learning any computer language is learning the syntax. If you manage to do that, with the experience you gained from previous projects/languages you might be able to create something working. At times you might feel down if the project doesn't work as expected.

What are some things that  can help make the process easier?

Video tutorials, experiments and searching questions and problems on Google is a very important resource.

3 0
2 years ago
Other questions:
  • To display or distribute information from a database, programmers or database administrators create ___ .
    12·1 answer
  • Hit and Slopes Program: A Write a program that can be used by a ski resort to keep track if local snow conditions for one week.
    15·1 answer
  • The box plot represents this data set. {16, 16, 16, 18, 18, 20, 24, 28, 30, 34} What value does the letter A represent on the bo
    8·2 answers
  • After reading passage “the incredible machine” why do you think the article has been titled so?
    13·1 answer
  • Tony is in charge of all presentations for a Fortune 500 pharmaceutical company. In addition to creating powerful and persuasive
    9·1 answer
  • The shortest compressed format of the ipv6 address 2001:0db8:0000:1470:0000:0000:0000:0200 is
    6·1 answer
  • Betty set up an account on a popular social networking website. she wants to know whether the privacy policy is effective for he
    14·1 answer
  • How do you know where the home row of the keyboard is?
    14·2 answers
  • If you are running a server , which of the follow operating system would be best suited ?window 10 or macOS
    8·1 answer
  • Who Has any idea How to code?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!