answer.
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]
2 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]2 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
Early Intel processors (e.g., the 8086) did not provide hardware support for dual-mode operation (i.e., support for a separate u
Firlakuza [10]

Answer:

Uneven use of resources

Explanation:

Potential problem associated with supporting multi - user operation without hardware support is:

Uneven use of resources: In a situation where we assign a set of resources to user 1 and if a new user comes, then it would be difficult to allocate new resources to him. The processor would get confused between the two users. And the tasks would not be completed. This can affect task processing.

8 0
1 year ago
The attack in which the attacker sends a forged packet with the same source IP address and destination IP address in which the v
Sergeeva-Olga [200]

Answer:

TEARDROP

Explanation:

Teardrop is a form of attack in which the attacker sends a forged packet with the same source IP address and destination IP address in which the victim may be tricked into sending messages to and from itself .

Teardrop attack also involves sending fragmented packets to a target machine in which the victim is been tricked into sending messages to and from itself. One of the fields in an IP header is the “fragment offset” field, indicating the starting position of the data contained in a fragmented packet relative to the data in the original packet.

7 0
2 years ago
To be a successful computer systems engineer, you must be proficient in programming languages and operating systems. Similarly,
Maslowich

Collectively, skills like the ones listed above are Technical skills. These skills refer to the Knowledge and ability to perform specific tasks. However, Soft skills are also important, because they relate to the ability to interact and communicate effectively with people.

6 0
2 years ago
Read 2 more answers
Harry wants to change the background of all of his presentation slides. Which slide will enable him to make this change to all t
Alexxx [7]

Harry would need to change the "color scheme" to change the background of all his presentation slides.

3 0
2 years ago
Read 2 more answers
In the context of the components of a typical expert system, _____ is a software package with manual or automated methods for ac
Pani-rosa [81]

Answer:

knowledge acquisition facility

Explanation:

In the context of the components of a typical expert system, Knowledge acquisition facility is defined as that component of an expert system that is responsible for providing an effective and efficient medium for collecting and incorporating relevant information such as data, new rules, relationships and facts used by the expert system.

6 0
1 year ago
Other questions:
  • Which of the following would be a considered a want rather than a need for most people?
    15·1 answer
  • A good website design combines which of the following elements? (select all that apply) powerful web server hardware components
    9·2 answers
  • Write a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The user shoul
    13·1 answer
  • Which of the following are true statements about digital certificates in Web browsers?I. Digital certificates are used to verify
    10·1 answer
  • While creating an animation, Gina has prepared a document stating the purpose and type of audience for the animation. What has
    6·1 answer
  • In a ____________________ attack, the attacker sends a large number of connection or information requests to disrupt a target fr
    14·1 answer
  • Write a program that has the following String variables: firstName, middleName, and lastName. Initialize these with your first,
    7·1 answer
  • ___________is used for drawing 3D objects in the field of Science and Engineering.
    12·2 answers
  • Ryan has made a presentation of ten slides, which he wants to display in sequence after a specific time interval. Which element
    5·1 answer
  • Plz help code practice for python
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!