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
Assume you have a subdirectory named datafiles directly under your current working directory, and you have two files named data1
Natasha_Volkova [10]

Answer:

Follows are the command which is used to copy file data:

CP data1 to data2 datafiles

Explanation:

In the above-given command code, we use the CP command, which is part of the Linux. In this command, we use  CP that stands for copying data1 file to data2 file for copying, and for the files to be pasted. This command also uses the "datafiles", which is used to provide the relative final destination path.

4 0
3 years ago
Which are examples of normative goals
Debora [2.8K]

Answer:

Goal-based decision making is goal generation together with goal-based planning

This decomposition of decision making in goal generation and planning raises several

questions, such as:

– How to represent beliefs? How to represent obligations? In this paper we represent

beliefs and obligations by rules, following the dominant tradition in deontic logic

(see e.g. [26,27]).

– How to develop a normative decision theory based on belief and obligation rules?

In this paper we introduce a qualitative decision theory, based on belief (B) and

obligation (O) rules.

6 0
3 years ago
What is included in a linked list node?
Annette [7]

Explanation:

In its most basic form, each node contains:

data, and a reference (in other words, a

link) to the next node in the sequence. A

linked list whose nodes contain two fields:

an integer value and a link to the next node.

The last node is linked to a terminator used

to signify the end of the list.

8 0
3 years ago
What type of ospf packet is used to actually send lsas between neighbors?
Marrrta [24]
<span>LSU OSPF packets are used to send LSAs between neighbors. </span>
<span /><span>
</span><span>Adjacencies are first formed by the OSPF neighbors before the LSAs are shared. When two OSPF neighbors exchange their known LSAs with the OSPF Database Description packets, the device does not know the actual LSAs. These are sent using Link Status Update pockets.</span>



3 0
3 years ago
Which component of a database management system (DBMS) is used to design elements of an application using a database, such as da
In-s [12.5K]

Answer: Application Generation

Explanation:

Application generation is the subsystem of database management system(DBMS) that helps in generation of range of transaction in-depth applications .

  • These application primarily focus on performing thorough steps got execution of transactions.
  • It is mostly commonly used by IT(Information technology) professionals programming languages, programming interfaces, data entry screen.

6 0
3 years ago
Other questions:
  • The contents of an array of type ______ can be displayed with the cout operator (without specifying an element). - 1 point(s)
    14·1 answer
  • Select Packet 10 in the Wireshark top pane and then answer the following questions: Did this handshake complete properly? What i
    7·1 answer
  • Drag the tiles to the correct boxes to complete the pairs.
    13·1 answer
  • These tools gather information from sources such as emails, text messages, and tweets and make the information instantly and pub
    14·1 answer
  • Which scenario depicts an ethical workplace practice by a business owner? A. sharing personal information of its employees with
    8·2 answers
  • What is the output of the following program? #include using namespace std; class TestClass { public: TestClass(int x) { cout &lt
    5·1 answer
  • Convert each of the following base 10 &amp; base 2 numbers in signed magnitude, one’s complement and two’s complement. Each of t
    8·1 answer
  • Hi, I just have a few questions from my digital tech assignment.
    14·2 answers
  • 9. If you want to change the Header text of any Form then which property will you use
    10·1 answer
  • Why are digital signals an accurate and reliable way to record and send information?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!