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
Mandarinka [93]
3 years ago
6

Method: public ArrayList diff(ArrayList list1, ArrayList list2) {} diff() method accepts two ArrayLists of Integer and returns t

he union of elements in two lists. (15 pts) Test case: list1: 1, 2, 3, 4, 5 list2: 3, 4, 5, 6, 7 This method should return an array list with elements 1, 2, 3, 4, 5, 6, 7
Computers and Technology
1 answer:
babymother [125]3 years ago
5 0

Answer:

(Assuming Java)

public ArrayList diff(ArrayList list1, ArrayList list2) {

   ArrayList<Integer> union = new ArrayList<>();

   for (int element : list1) {

       union.add(element);

   }

   for (int element : list2){

       if (!union.contains(element)) {

           union.add(element);

       }

   }

   return union;

}

Explanation:

Create an ArrayList that has the union of list1 and list2.

First for loop copies all elements into the union array list.

Second for loop adds all elements that are not yet in the union arraylist to the union arraylist.

(Keep in mind that I assume that you mean a mathematical union, so no duplicates. If this is not what you mean, remove the if statement in the second for loop)

You might be interested in
Which statements are true? Select 4 options.
kolezko [41]

Answer: All of the answers are correct EXCEPT "An instance of a class cannot be changed after it is created.

Explanation: I've done the problem. Also, if you have an instance of a class, you can no longer change it. It is frozen in time as that one instance. If had a class defining pets and you made an instance dogA where the pet was a brown medium sized dog, dogA would always be a brown medium sized dog. I think, at least.

4 0
3 years ago
A database with a(n) _______________ data structure can easily handle a many-to-many data relationship. hierarchical network rel
AlexFokin [52]
Hello <span>Jeffstephens124</span><span>


Answer: A database with a(n) network data structure can easily handle a many-to-many data relationship. 

Hope this helps
-Chris</span>
3 0
4 years ago
Which of the following journals is not aimed at the public as well as scientists?
svet-max [94.6K]
"Journal of the IEST" is not aimed at the public as well as scientists since it deals primarily with very specialized and esoteric studies, and uses language that most non-scientists wouldn't understand. 
7 0
3 years ago
What is the correct order of precedence of the mathematical operators?
LenaWriter [7]
A common technique for remembering the order<span> of </span>operations<span> is the abbreviation "PEMDAS", which is turned into the phrase "Please Excuse My Dear Aunt Sally". It stands for "Parentheses, Exponents, Multiplication and Division, and Addition and Subtraction".</span>
7 0
4 years ago
True / False
Tju [1.3M]

Answer:

TRUE, The PC is always incremented by the same amount in fixed-length instruction set architectures.

Explanation:

Its TRUE that Program Counter ( PC ) is always incremented by the same amount in fixed - length instruction set architectures ( fixed length ISA) . As the instruction set length is fixed in fixed - length instruction set architectures, the Program Counter to fetch the next instruction set it has to be incremented by fixed length. This fixed length depends on the hardware of the architecture (the number of bytes each machine word contains and number of machine words per memory location)

7 0
4 years ago
Other questions:
  • Sean is white hat hacker, who is demonstrating a network level session hijack attacks and as part of it, he has injected malicio
    6·1 answer
  • Brad teaches an accounting class, and he created a PowerPoint presentation from a Word outline for his class. This Word outline
    14·1 answer
  • Why is it useful to have host-based firewalls?
    5·1 answer
  • ZeroIt is a function that takes one argument and returns no value. The argument is a pointer to int. The function stores the val
    15·1 answer
  • &gt;&gt;&gt; from hog import *
    15·1 answer
  • What is indexing ? How does it make search engines work more efficiently?
    15·1 answer
  • Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in
    9·1 answer
  • What will be the output of following python code? a,b=3,4 a,b,c=b,a+3,b-1 print(a,b,c)​
    7·1 answer
  • What is the full form of MPEG?<br> The full form for MPEG is ________.
    9·1 answer
  • What rpm command can be used to list the full paths for files within the bash package?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!