Write a method intersect that accepts two sorted array lists of integers as parameters and returns a new list that contains only the elements that are found in both lists.

Answers

Answer 1

Answer:

Explanation:

The following code is written in Java. It creates a function called equalElements that takes two ArrayList of integers as parameters loops through both of them to find the elements that are equal in both and then adds those elements to a new ArrayList called repeated. Then the ArrayList is returned to the user.

public static ArrayList<Integer> equalElements(ArrayList<Integer> arrOne, ArrayList<Integer> arrTwo) {

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

               for (int x: arrOne) {

                       for (int i: arrTwo) {

                               if (x == i) {

                                   repeated.add(x);

                                   break;

                               }

                       }

               }

               

               return repeated;

}


Related Questions

A system administrator at Universal Containers created a new account record type. However, sales users are unable to select the new record type when creating new account records. What is a possible reason for this? (Choose 2)

Answers

Explanation:

We have these reasons below as the

The reason why sales users are not able to select the new record type while they are trying to create a new account:

1. The users profile does not contain the record type yet. That is, this record type has not been added to the profile of the sales user.

2. This record type is yet to be activated.

Other Questions
Prince Company owns 104,000 of the 130,000 shares outstanding of Serf Corporation. Serf Corporation sold equipment to Prince Company on January 1, 2017 for $740,000. The equipment was originally purchased by Serf Corporation on January 1, 2016 for $1,280,000 and at that time its estimated depreciable life was 8 years. The equipment is estimated to have a remaining useful life of four years on January 1, 2017. Both companies use the straight-line method to depreciate equipment. In 2018 Prince Company reported net income from its independent operations of $3,270,000, and Serf Corporation reported net income of $820,000 and declared dividends of $60,000. Prince Company uses the cost method to record the investment in Serf Company. Required: A. Prepare, in general journal form, the workpaper entries relating to the intercompany sale of equipment that are necessary in the December 31, 2018 consolidated financial statements workpapers. The population of a town was 25000 in the 2000 census and and 30000 in 2010 census. By what percent did the population increase Mobile cameras are now of a higher quality than when they first arrived on the market. Describe the difference inresolution that has come about and how that has led to higher photo quality. There are windows for every 3penguins.There are windows for every 11 penguin. Two cars leave the same parking lot, with one heading north and the other heading east. After several minutes, the eastbound car has traveled 2 kilometers. If the two cars are now a straight-line distance of 4 kilometers apart, how far has the northbound car traveled? (use){Pythagorean theorem}[tex]a^{2} +b^{2} =c^{2}[/tex] At a bake sale, a total of 80 cookies were sold. If the ratio of chocolate chip cookies sold to oatmeal cookies sold was 9 : 1, how many chocolate chip cookies were sold? c)How many quarters make a whole?d) How many fifths make a whole?e) How many tenths make a whole?nta Excel in Mathematics - Book 3108 HELP QUICK PLSSThe shadow of the tree is 40 feet long. A yard-stick placed next to the tree casts a 6 foot shadow. How tall is the tree? I NEED HELLPPPPPPPP Can someone help me out pls? please what is the adaptive behaviour of a mosquito What was one result of the Black Plague in England? What's the y intercept 1What happens to the curve when the standard deviation is increased? What does that do to the area under the curve?2What happens to the curve when the standard deviation is decreased? What does that do to the area under the curve? The quotation below is from Schenck v. United States, a famous Supreme Court decision.The most stringent protection of free speech would not protect a man in falselyshouting fire in a theatre and causing a panic. ... The question in every case iswhether the words used ... are of such a nature as to create a clear and presentdanger... that Congress has a right to prevent.Based on this decision, which conclusion can be made about our constitutional rights?Under our Constitution, freedom is more important than safety.Congress has the power to limit our freedom of speech whenever it wishes.None of our rights would be secure if we treated everyone's rights as unlimited.Because our freedom of speech is guaranteed by the First Amendment, it cannot be restricted. Solve for the value of the variable: 7x+ 10 = 4x + 16Enter the answer Math help please 2Will give brainest Which function is nonlinear?mark as brilliant! help Johnson Inc. is a job-order manufacturing company that uses a predetermined overhead rate, based on direct labor hours, to apply overhead to individual jobs.For the current year, estimated direct labor hours are 95,000 and estimated factory overhead is $617,500.The following information is for September of the current year:September 1, inventories:Materials inventory $ 7,500Work-in-process inventory (All Job A) 31,200Finished goods inventory 67,000Material purchases 104,000Direct materials requisitioned:Job A 65,000Job B 33,500Direct labor hours:Job A 4,200Job B 3,500Labor costs incurred;Direct labor ($8.50/hour) 65,450Indirect labor 13,500Supervisory salaries 6,000Rental costs:Factory 7,000Administrative offices 1,800Total equipment depreciation costs:Factory 7,500Administrative offices 1,600Indirect materials used 12,000Job A was completed during September and Job B was started but not finished.Required:1. What is the total cost of Job A?2. What is the total factory overhead applied during September?3. What is the over-applied or under-applied overhead for September? Which of the following statements is FALSE?a.Radical Republicans began raising state and local taxes to rebuild government and public services after the Civil War. b.Only 10% of Texans earned their living from farming before the Civil War.c.Texas was 8th among Southern states for cotton production.d.Governor Davis opposition to government participation in railroad construction slowed progress in Texas. Please select the best answer from the choices providedABCD