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
notka56 [123]
3 years ago
10

In this exercise, you will create a couple of helper methods for ArrayLists in a class called ArrayListMethods.

Computers and Technology
1 answer:
nata0808 [166]3 years ago
5 0

Answer:

package lab1;

import java.util.ArrayList;

import java.util.Iterator;

public class ArrayListMethodsTester

{

public static void main(String[] args)

{

ArrayList<String> stringArray = new ArrayList<String>();

stringArray.add("This");

stringArray.add("is");

stringArray.add("an");

stringArray.add("ArrayList");

stringArray.add("of");

stringArray.add("Strings");

System.out.println("Printing the arraylist:");

ArrayListMethods.print(stringArray);

System.out.println("\nArrayList is condensing:");

ArrayListMethods.condense(stringArray);

ArrayListMethods.print(stringArray);

System.out.println("\nArrayList is duplicating:");

ArrayListMethods.duplicate(stringArray);

ArrayListMethods.print(stringArray);

}

}

class ArrayListMethods

{

static void print(ArrayList stringArray)

{

  Iterator it = stringArray.iterator();

  while (it.hasNext())

     System.out.println(it.next() + " ");

     

}

static void condense(ArrayList stringArray)

{

  int length=stringArray.size();

     

  ArrayList cloneArray=(ArrayList) stringArray.clone();

     

  stringArray.clear();

  StringBuilder sb=new StringBuilder("");

     

  for (int i = 0; i < (length/2); i++)

  {

      sb.append(cloneArray.get(i));

      sb.append(" ");    

  }

  stringArray.add(sb);

     

  StringBuilder sb1=new StringBuilder("");

  for (int i = (length/2); i < length; i++)

  {

      sb1.append(cloneArray.get(i));

      sb1.append(" ");    

  }

  stringArray.add(sb1);

  }

static void duplicate(ArrayList stringArray)

{

  for (int i = 0; i < stringArray.size(); i+=2)

  {

      stringArray.add(i+1,stringArray.get(i));

  }

}

}

Explanation:

  • Get the length of the arraylist  to copy the array into another arraylist .
  • Empty the array so that new content can be stored in it .
  • Use a loop to half of array_list.
  • Use a loop from half of array_list to the end of arraylist and  append all into a single string.
You might be interested in
My home PC has IP address 192.168.1.22 and connects to the Internet through a NAT router. Assume I am downloading a web page fro
alekssr [168]

Answer and Explanation:

There are three sections to the inquiry.  

1. what occurs inside the PC or host when a bundle is produced by an application.  

2.how it goes from one host that is a source to another host that is a goal with numerous switches sitting in the middle.  

3.what goes inside goal have when it gets a parcel on the system.  

how about we examine individually  

Handling bundle at source machine:  

The application creates a bundle to be sent on the system and sends it to the layer beneath.  

The following layer is known as a vehicle layer which oversees start to finish correspondence between two machines. The convention utilized can be TCP or UDP. What is the contrast between these two conventions is another subject by and large.  

When the parcel is framed at the vehicle layer, it is sent to the system layer which includes source and goal IP in the bundle. A most significant field which is included at IP or system layer is Time To Live (TTL) which is utilized by middle switches/changes to choose if a parcel should be sent or not. (How goal IP is found?)  

After the system layer, the parcel arrives at the information connection or MAC layer, where the source and goal MAC address of machines are included. We will perceive how these fields change between each two neighbors. (How goal MAC is found?)  

The information interface layer pushes this bundle to the physical layer where it is sent as a flood of "0" and "1" on the physical medium accessible.  

Preparing a bundle at switch:  

Steering  

There are three cases which may happen when the switch investigates the directing table for goal IP  

1. On the off chance that there is a section relating to goal IP, we get the interface name the parcel ought to be sent to.  

2. On the off chance that there is no immediate passage, at that point IP is changed over into organize IP utilizing the veil and afterward checked once more. It ought to be noticed that the longest prefix match to locate the best sending interface.  

3. In the case of nothing matches, at that point the switch just advances it to the default goal designed.  

Sending  

Epitome  

Preparing parcel at the goal have  

The parcel is gotten at arrange card, physical layer, which produces a hinder to CPU and CPU peruses bundle in,  

At the information connect layer, goal MAC address is verified whether the parcel is bound to this machine, If indeed, the bundle is sent up to the system layer.  

At the IP layer, parcel approval like checksum confirmation, and so on is done and afterward gave to the applicable vehicle layer.  

Transport later at that point gives it to the fitting port with the goal that it arrives at the right application.

5 0
2 years ago
A _ shows the end of a page . ​
marta [7]

Answer:

page break shows the end of a page.

4 0
2 years ago
Read 2 more answers
Drag the tiles to the correct boxes to complete the pairs.
sertanlavr [38]

Answer:

Explanation:

IaaS - storage and network devices

SaaS - software upgrades and patches

MaaS - monitoring tools

PaaS - virtual computing platform

7 0
2 years ago
The rock cycle _____.
creativ13 [48]
The best and most correct answer among the choices provided by the question is the second choice. The rock cycle <span>changes and recycles Earth's rocks. </span>I hope my answer has come to your help. God bless and have a nice day ahead!
8 0
3 years ago
Which is the most important reason you should properly cite information that you obtain from an Internet search? Question 2 opti
Pepsi [2]
It is to avoid plagiarizing someone else's work
3 0
3 years ago
Other questions:
  • Cleo finds herself frequently searching for messages from particular senders or with specific subjects. What should she create
    5·1 answer
  • Which individual of the following would be most likely to be directly concerned with web security?
    14·2 answers
  • Bushman and bonacci (2004) found that prejudiced participants were ____ likely to return a lost e-mail that had been addressed t
    5·1 answer
  • Why computer is known as data processing system?
    14·1 answer
  • HELP PLEASE!!! I do online school, someone is in another state wanting to help me. No not do my work for me but view what I view
    6·1 answer
  • A class is a _____, which encapsulates _____ and _____. (Points : 2) programming language construct; attributes; behavior
    7·1 answer
  • A palindrome is a string that reads the same both forward and backward. For example, the string madam is a palindrome. Write a p
    13·1 answer
  • Instructions
    8·1 answer
  • Identify a characteristic that is a disadvantage of cloud-based hosting.
    11·1 answer
  • you want to upgrade your windows 10 professional computer to windows 11 professional. you begin by checking the hardware and dis
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!