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
​When preparing a representative sample from a list of 200 customers who complained about errors in their statements, a _____ co
svetoff [14.1K]

Answer: Stratified sample

Explanation:

For preparing samples of various data of companies and enterprises we need to apply probability distribution to different samples of data. Here in the question we are to apply a representative sample from a list of 200 customers who have complained about errors in their statement. So here we can apply stratified sampling where we can divide the 200 customers into separate groups. These sub groups of the customers are known as stratas. These stratas are selected based on certain characteristics which can be identified among the customers group. Here we can form subgroups based on the type of complain that has been lodged by the customer and selecting 5 customers from four zip codes. Then it would be easy to apply probability distribution to the sub groups to derive information from them.

This process would also enable a more easier and cheaper way of sampling the customer data.

7 0
3 years ago
When excel imports an access table, the data is placed in a worksheet _____?
ratelena [41]
Book is the answer!!!!!
3 0
3 years ago
When typing lists in a document, you must use single-spacing between each item in the list.
dexar [7]
False False true
Hope it helps
4 0
2 years ago
JAVA
Umnica [9.8K]

import java.util.Scanner;

public class JavaApplication58 {

   

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Enter a positive integer:");

       String num = scan.nextLine();

       for (int i = num.length()-1; i >=0; i--){

           System.out.println(num.charAt(i));

       }

       

   }

   

}

I hope this helps!

5 0
3 years ago
Example of Bandwidth Analogies: using Pipe
skelet666 [1.2K]

Answer:

Bandwidth describes the maximum data transfer rate of a network or Internet connection. ... For example, a gigabit Ethernet connection has a bandwidth of 1,000 Mbps (125 megabytes per second). An Internet connection via cable modem may provide 25 Mbps of bandwidth.

7 0
2 years ago
Read 2 more answers
Other questions:
  • Why was the personal computer an important invention?
    7·1 answer
  • A. Draw a flowchart or write pseudocode to represent the logic of a program that allows the user to enter an hourly pay rate and
    8·1 answer
  • QUESTION
    10·1 answer
  • What is an advantage of a computer network ? networked
    13·2 answers
  • What is Human Dignity
    12·1 answer
  • Write a Java program that generates GUI (Graphical User Interface). Your program should provide labels and textfields to a user
    9·1 answer
  • Could someone please explain to me the an electrical circuit.
    13·2 answers
  • My pc suddenly freezes and i can't open any apps or task manager. Apps do not open at all and if i restart from the start it get
    9·1 answer
  • Plsss help me plsssssss
    11·1 answer
  • Which generation of computer is most popular and why?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!