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
HELP I WILL MARK BRAINLIEST!!! I NEED ASAP!!!
Alex777 [14]

#This is a way without a loop

friends = list(map(str,input("Enter Names: ").split()))

print(sorted(friends))

#This is a way with a loop (for&&while)

friends = list(map(str,input("Enter Names: ").split()))

cool = True

while cool:

   cool = False

   for i in range(len(friends)-1):

       if friends[i] > friends[i+1]:

           coo = friends[i]

           friends[i] = friends[i+1]

           friends[i+1] = coo

           cool = True

print(friends)

4 0
3 years ago
Calculate the shear stress (lbf/in^2) for a given normal stress (lbf/in^2) that is applied to a material with a given cohesion (
LenaWriter [7]

MOHR-COULOMB FAILURE CRITERIA:

In 1900, MOHR-COULOMB states Theory of Rupture in Materials which defines as “A material fails due to because of a critical combination of normal and shear stress, not from maximum normal or shear stress”. Failure Envelope is approached by a linear relationship.

If you can not understand the below symbols see the attachment below

 f   f ()  

Where:      f = Shear Stress on Failure Plane  

       ´= Normal Stress on Failure Plane

 See the graph in the attachment

For calculating the shear stress, when Normal stress, cohesion and angle of internal friction are given. Use this formula:   shear stress =  f  c   tan 

Where,  

• f  is Shear Stress on Failure Plane

• c  is Cohesion

•  is Normal Total Stress on Failure Plane

•  is Friction Angle

8 0
3 years ago
​ A webpage gets a new modification date for all of the following EXCEPT:
riadik2000 [5.3K]

Answer:

a.  ​daily

Explanation:

A webpage gets a new modification date whenever any change is made. This is irrespective of whether the change is large or small, significant or insignificant. Any update to the webpage will change its modification date. But this change will not be carried out automatically everyday unless an actual modification is carried out on that day.Otherwise it will continue to carry the modification date corresponding to the day of last update.

4 0
2 years ago
1. Information integrity ensures that data can be modified only by appropriate mechanisms.
GrogVix [38]

Answer:

1. True

2. True

3. False

4. False

Explanation:

1. Information integrity is a term in computer business that describes the degree of accuracy, reliability and dependency of an information content, process and system.

The main purpose of Information integrity is to prevent or protect information from accidental or intentional but unauthorized changes.

Hence, it helps to ensure that data can be modified only by appropriate mechanism.

2. Pairing threats with vulnerabilities is a pair of risk analysis, that sets to determine the type of vulnerabilities a system or organization has, which can be paired with valid threats. Hence, the kind of risk involved in the vulnerability threats, can then be addressed.

3. Knowledge based identification (authentication) system which involves password or PIN are the most common form of authentication methods. Ranges from different devices such as phones and PC to platform such as website.

4. Biometric is a type of user authentication that relies on the measurement and calculation of the shape of the body, such as fingerprint, palm veins, face recognition, DNA, palm print, hand geometry, iris recognition, retina and odour/scent. It is often referred to as Physiological characteristics of Biometric system.

6 0
3 years ago
Read 2 more answers
Which disclosure paradigm has as its assumptions that 1) an attacker will learn little or nothing from disclosure; 2) Disclosure
nekit [7.7K]

The  disclosure paradigm has as its assumptions that an attacker will learn little or nothing from disclosure is known as Open source.

<h3>What is open source?</h3>

An  Open source is known to be a term that connote that is said to be an Open source software set up to be publicly used by people.

Therefore, The  disclosure paradigm has as its assumptions that an attacker will learn little or nothing from disclosure is known as Open source.

Learn more about Open source from

brainly.com/question/6065176

#SPJ1

3 0
2 years ago
Other questions:
  • What task did the u.s. government undertake that many people identify as the birth of the internet
    5·2 answers
  • Schools are businesses that need to install software on a large number of computers can usually obtain a ______
    13·1 answer
  • ​In addition to joint application development, another popular user-oriented method is _____, which resembles a condensed versio
    14·1 answer
  • The house belives that works should be compensated for the loss of jobs due to automation? Describe it in against motion of the
    15·1 answer
  • Organizing speech ideas according to physical space, direction, or location calls for a _____ organizational pattern.
    11·1 answer
  • Ethan wants to change the font in his document. He should _____.
    8·1 answer
  • How do you think Beyoncé choreography has/will influence the future of dance?
    9·2 answers
  • Look at the picture ​
    13·2 answers
  • Please help me I don’t know what I’m doing wrong.
    12·1 answer
  • Please solve this in JAVA<br><br> Please see the attachment
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!