Make a String ArrayList.Then write a Java method that swaps the first and last elements.

Answers

Answer 1

Answer:In order to swap elements of ArrayList with Java collections, we need to use the Collections.swap() method. It swaps the elements at the specified positions in the list.

Declaration −The java.util.Collections.swap() method is declared as follows

public static void swap(List <?> list, int i, int j)

where i is the index of the first element to be swapped, j is the index of the other element to be swapped and list is the list where the swapping takes place.

Explanation:

import java.util.*;

public class Example {

  public static void main (String[] args) {

    ArrayList<Integer> list = new ArrayList<Integer>();

     list.add(10);//0

     list.add(20);//1

     list.add(30);//2

     list.add(40);//3

     list.add(50);//4

     System.out.println("Original list : " + list);

     Collections.swap(list, 4, 0); // swapping element at index 3 i.e. 50 and index 1 i.e. 10

     System.out.println("List after swapping : " + list);

  }

}


Related Questions

What is the value of X when line 30 is executed in the program below:
10 X = 5
20 X = X + 5
30 X = X/5 + X
40 X = X * 5
50 X = (X - 5)/5

this is for qbasic btw

any helpis appreciated pls only correct answers

Answers

Answer:

X = 12

Explanation:

The primary value of X is 5. In line 20 X = X + 5, which is saying the primary value of X ,5, + 5, this is going to return the value of X to now become 10. Now the primary value of X in the program has changed to 10.

In line 30 X = X/5 + X, keeping in mind that the new primary value is not 5 but 10. So now line 30 is saying X = 10/5 + 10. This return the value of X to be 12.

what are storage devices? write two such devices​

Answers

Answer:

two types of storage devices used with computers a primary storage device such as r a m and the secondary storage device such as a hard drive secondary storage can be removable internet or external

Explanation:

hope it is helpful for you please make me brilliant only if you like this answers

Answer:

Devices which stores computer data and information are called storage devices

ex - RAM ( random excess memory)

ROM ( read only memory).

CS902 Module3 Homework1

Answers

That’s a Great question

ConstructalogicnetworkthatrealizesthethreeinputORfunction(A+B+C) using only two input NAND gates (AB)’. Prove that your design works correctly by annotating the output of each NAND gate with its Boolean equation.

Answers

Answer:

I think that the grade my teacher gave me on my test is wrong

what is a characteristic of an effective scrum master

Answers

It is a characteristic of an effective master that Knowledgeable. The exceptional Masters have the technical, market, or precise expertise to assist the group in its goal.

What are the traits of the Master?

This is a given, in any role. However, as you're listening, comprehending, repeating, summarizing, energizing, observing, writing, simplifying, critiquing, suggesting, asserting, , presenting - all in one.

A powerful Master is a group-primarily based totally servant chief who: Exhibits leadership – Exhibits the behaviors of a Leader with a Mindset. Helps the group embody Core Values, undertake and follow Principles, and put in SAFe practices.

Read more about the master:

https://brainly.com/question/4763588

#SPJ1

A set of photographs has been taken for a wedding. All the guests are to be sent digitally
stored copies through the ordinary postal service. There are fifty photographs and each
photograph is between 1.8 and 2.5 megabytes in size.
Work out the maximum storage space required for a set of photographs. State, with a
reason, a suitable medium to use for the copies to be sent to the guests.

Answers

In the case above, the maximum storage space will be 125 megabytes.

Note that:

Medium size: CD / low capacity flash memory.The Reason is because it is good for mailing and less expensive to get.

What is storage space?

This is known to be the amount of place or area a phot can occupy in terms of photography.

Note that, In the case above, the maximum storage space will be 125 megabytes.

Note that:

Medium size: CD / low capacity flash memory.The Reason is because it is good for mailing and less expensive to get.

Learn more about photographs from

https://brainly.com/question/25821700

#SPJ1

Algorithm to find odd integers between 1 and49 ​

Answers

Answer:

1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49.

the most popular input device for computer game is called?

Answers

Answer:

joystick

Explanation:

A joystick is an input device that monitors and transmits motion input to the Processor. It monitors any minute changes in direction using a central pivot, then transmits this input to be analyzed and generally operates another device. A joystick is a type of input device which is often utilized to operate gaming programs or graphics programs. A joystick is often used to control a device or a character in a computer software. It is used to operate videogames and may be used to play games designed for gaming platforms or computer games. A joystick is an input device with a pivoting center handle that communicates the angle and direction to the device it is controlling. It helps to engage with your games and has several real-world applications.

what is the function of computer?​

Answers

[tex]\huge\purple{Hi!}[/tex]

the four basic function of a computer are input, storage, processing and output.

1.- Make a program that loops and perform powers of 5 on each loop.
In each lap the operator is asked IF YOU WISH TO CONTINUE (1 or 0) if the operator enters a zero it will no longer continue to spin. IN CODE C++

Answers

A program that loops and performs powers of 5 on each loop.In each lap the operator is asked IN CODE C++ the C++ Program for the given hassle announcement is as follows:#include the use of namespace std.

What is the energy of a variety of?

The energy of a variety of says how usually to apply the range in a multiplication. Powers also are known as Exponents or Indices. For example, eight^2 might be known as “eight to the energy 2” or “eight to the second one energy”, or simply “eight square.

C++ Program for the given hassle announcement is as follows:#include the use of namespace std;int main() > base;cout << "nEnter the exponent: ";     //asks the user for keyboard input for exponent cin>>exponent;  for (int i = 1; i <=exponent; i++)    //iterate {through|thru|via">via 1 until exponent {       num=num*base; //base is multiplied (e.g. 2*2*2.....n) until n, wherein n is exponent    } cout <<"n"<strength of "<go back 0;}Sample Output:Stdin Inputs

Read more about the loops :

https://brainly.com/question/26497128

#SPJ1

After Daniel performed poorly on a test, his teacher advised him to do some self-reflection to figure out how he could get a better score on the next test.

Which actions should Daniel take? Check all that apply.

analyze the content that he knows well
think about whether he should study differently
forget about the test behind him and concentrate on the next one
ask the teacher for some extra help outside of class
go out with his friends to put the poor grade behind him
study the questions he missed and think about why he missed them

Answers

Daniel gives more and more time to self-reflection and improves the mistakes he was doing in the last exam.

What is self-refelection?

Reflecting on oneself is similar to gazing in a mirror and reporting what you see. It is a method of evaluating your work habits, study style, and self. To think about something is the definition of reflection, given simply.

When Daniel didn't do well on an exam, his teacher suggested that he think about his performance to see how he may perform better on the upcoming test.

Examine the material he is familiar with. Consider whether he needs to change his study strategy. Request extra assistance from the instructor outside of class.

Examine the questions he didn't get right and consider why. Self-reflection is the process of assessing one's performance to identify any problem areas that require improvement.

Hence, daniel gives more and more time to self-reflection and improves the mistakes he was doing in the last exam.

To learn more about self-reflection refer;

https://brainly.com/question/14754364

#SPJ1

Answer:

Explanation:

a analyze the content that he knows well

b think about whether he should study differently

d ask the teacher for some extra help outside of class

f study the questions he missed and think about why he missed them

You are preparing to communicate to an audience about analysis project. You consider the roles that your audience members play and their stake in the project. What aspect of data story telling does this scenario describes?

Answers

The aspect of data story telling does this scenario describes is audience engagement.

What is Audience engagement?

This is known to be  user engagement and it is a term that connote  the cognitive, emotional, or affective form of experiences that users do get or have with media content or any kind of brands.

Note that in the case above, the aspect of data story telling does this scenario describes is audience engagement.

Learn more about project from

https://brainly.com/question/13374052

#SPJ1

1.Which thematic group uses technology to direct the behavior of dynamical systems, ensuring that they behave in a predictable manner?
2.Which thematic group creates circuits with miniature, packaged components that directs and control electricity?

a.Communication Systems
b.Control Systems
c.Computer Systems
d.Energy Systems
e.Electronic Systems

Answers

Dynamic systems are governed by control systems, whereas electronic systems contain the minuscule parts required to conduct electricity. Option E is correct.

What are groups?

People who concentrate on the same issue or idea form thematic groups. Individuals with experience in diverse systems make form thematic teams working on various initiatives and concepts.

In order to achieve the intended outcome, the control system's main purpose has been to govern dynamic systems.

The electronic system theme group's job is to put electronic miniatures in systems that act as power-control mechanisms. Thus, option E is correct.

Learn more about thematic groups. here:

https://brainly.com/question/14835569

#SPJ1

3.12 LAB: Output range with increment of 5 Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 5 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 10

Answers

The INPUT code of the given programme in Java would be as given below:

In this first we are taking input of two integers j and k from the user and then performing the required operations over it

import java.util.

Scanner;  public class LabProgram {    

public static void main(String[ ] args) {  

Scanner scnr = new Scanner(System.in);        

 int i,j;        

 i  = scnr.nextInt();        

 j = scnr.nextInt();        

if(i<=j) {            

int k = i;            

while (k <= j) {                

System.out.print(k + " ");                

 k = k + 5;            

 }            

 System.out.println();        

 }        

 else{            

 System.out.println("Second integer can't be less than first.");                  

}    

}

}  

Learn more about Java Programming here:

https://brainly.com/question/18554491

#SPJ10

When creating an if() statement, when are curly braces required?
A. when there is only one statement line related to the test condition
B. when there are two or more statement lines related to the test condition
C. never
D. always

Answers

Answer:

B. When there are two or more statements lines related to the test condition.

Sorry if I got it wrong.

Choose the expression that belongs in the blank in order to ask the user the question shown.

>>> answer = input(_____)
What is your name? Juan

Answers

Answer:

"Juan"

Explanation:

If this is script, than that should be the correct argument.

Give me an answer. How to hack somebody click 'disabled​​​​​​​' to my office wifi? I can't use it no longer.​​​​

Answers

How to hack somone is illegal but for study purposes there is yt tutorials that I recommend You watch because hacking is not simple and it requires a pc or laptop There is multiple ways to hack somone as well A commAn way for hacking is to self fake links

Operational level management can be supported by the systems except Select one: 01. Transaction Processing System 2. Manufacturing Information System 3. Executive support system 4. Financial management system ​

Answers

Answer:

01×3=3

=3

Explanation:

mousamyuig9uuygytyugghbhhbhhbhh

What are key objectives of DevOps at Accenture?

Answers

The key objectives of DevOps at Accenture is simply to deliver services faster, with higher quality and with security built in.

What are DevOps?

DevOps can be defined as a set of tools, processes, practices, and a cultural philosophy that are combined so as to help in automating and integrating the processes that exist between software development and information technology (IT) teams.

This ultimately implies that, the key objectives of DevOps is focused on the ability of Accenture to deliver software applications and services at high velocity, with higher quality and with security built in.

Read more on DevOps here: https://brainly.com/question/24306632

#SPJ1

15. How many PC’s can be connected to a UPS?

Answers

Answer: Depends on the power of the computer /computers and the UPS

Explanation: For someone who had a big connected network of computers and printers we would plug the computer or server into the UPS as well as the monitor and sometimes a printer sometimes the monitor was plugged into the wall

When you get a UPS you must plug it in for a certain time could be hours or even a day.  A USP has a big battery in it and you must charge it (sometimes it comes semi-charged but you must plug it in to strengthen it. )

there are two connector wires that you affix to the battery and you must put a lot of strength into it to make it secure.

So in closing, you can get away with two like a desktop and a laptop.

Read your documentation that comes with the UPS

Suppose you have 10 image files, each taking up 300 KB. About how many MB of space do they take up
overall?

Answers

Answer:

b

Explanation:

porque es la única a la cual puedes poner ssi querés sabe neibw idbe

Answer:

3MB

Explanation:

300KB×10files=3000KB

1MB=1000KB

so:

3000KB=3MB

what are output devices? name any two common output devices.​

Answers

Answer:

Devices which display the result of the command or which gives outputs are called output devices

ex monitor - it gives display of all the command performing in the computer..

Answer:

An output device is any hardware device used to send data from a computer to another device. its common output device are video,audio.

identify four input devices that can convert hard copy pictures or into a digital format ​

Answers

Answer:

(a) graphics tablet

(b) scanner

(c) MICR

(d) OMR

Which of the following keys on the keyboard is used to quickly indent text

Answers

you have to use tab on the keyboard


- factors to consider when buying a computers

Answers

Answer:

money

Explanation:

for working for socializing with others

What will happend when I got a BSOD in Windows?

Please answer this question. I'll give You 50 points for free!

Answers

Answer:In Windows OS, the Blue Screen of Death or BSOD appears after a serious system crash that indicates there is some major issue with your PC. Typically, the BSOD—also referred as STOP error — is related to critical hardware and driver misconfiguration, damage, and failure.

Explanation:

Answer:

A blue screen error (also called a stop error) can occur if a problem causes your device to shut down or restart unexpectedly. You might see a blue screen with a message that your device ran into a problem and needs to restart.

What is not a computer software?
a. web browser
b. powerpoint
c. motherboard

Answers

Answer:

Motherboard

Explanation:

Its a device in the computer that helps it run while powerpoint and web browser are just things you can do with your computer to make or create information.

**HELP ME PLS**

A report tried "Employees in Company A contains the names of employees in descending alphabetical order, with the
number of years each employee worked at the company. Which statement is true? A.The report is grouped only because it gives information about employees by number of years of employment.

B.The report is soned only because it gives information about employees by number of years of employment.

C.The report is grouped only because it organizes the names of the employees in alphabetical order.

D.The report is sorted only because it organizes the names of the employees in alphabetical order.

Answers

The true statement is the report is grouped only because it gives information about employees by number of years of employment.

What is a group report?

Group reporting is made up of consolidation method and analytical reports and it gives information on the output of a firm.

Note that since there are different ranges of employment years, the report need to be grouped and as such, The true statement is the report is grouped only because it gives information about employees by number of years of employment.

Learn more about group report from

https://brainly.com/question/13628349

#SPJ1

When replacing a defective switch what is necessary characteristic of a new switch

Answers

The complete question is :

When replacing a defective switch, what is a necessary characteristic of the new switch?

Select one:

a. Greater number of poles and throws than the original switch

b. The same number of positions as the original switch

C. Identical cover plate as the original switch

d. Greater current ratings than the original switch

So, according to it the correct answer is option d. Greater current ratings than the original switch.

What is a switch?

A switch is a component of physical circuitry that controls the flow of signals. A switch or toggle switch enables the opening or closing of a connection. The switch permits a signal or power to pass through the connection when it is opened. The switch cuts the circuit connection and halts the flow when it is closed.

Learn more about switches here https://brainly.com/question/14883923

#SPJ10

Two negative reviews and no positive reviews is enough to consider the website to have a negative reputation.

Answers

Two negative reviews and no positive reviews is enough to consider the website to have a negative reputation: False.

What is reputation?

In Computer technology, reputation can be defined as a metric which is used to determine the quality of a particular website, especially based on the opinions and ratings by its end users.

In this context, we can infer that two negative reviews and no positive reviews isn't an enough metric to consider a website as having a negative reputation.

Read more on negative reputation here: https://brainly.com/question/2343924

#SPJ1

Other Questions
The table shows the population of a small town over time. The function P = 10,550(1.1)x models the population x years after the year 2000.A 2-column table with 5 rows. The first column is labeled years after 2000, x with entries 0, 3, 4, 7, 10. The second column is labeled population, P with entries 10,5000; 14,000; 15,500; 20,500; 27,000.For which year would this model most likely be sufficient to make a prediction of the population?1950200520252050 NEED HELP ASAP!!!!!Triangle ABC and DEF are similar. Answer the following questions:a. What relationship can you write for the angles of these two triangles?b. What is the length of the missing side? This food web is for a community near a small lake.rabbitfernfoxsquirrelhawkIf the squirrels in this community died out, how would this change be mostlikely to affect another organism in the community?A. The rabbits would lose their food source.B. The hawks would leave or find another food source.C. The ferns would invade other ecosystems.D. The foxes would have more space and food. Which step is not part of a normal convection cycle? A. Air flows from a high-pressure area to a low-pressure area. B. A low-pressure system forms due to unequal heating. C. Cooled air sinks toward the surface. D. Warmed air rises, creating a high-pressure system below. Im stuck on this to could you guys explain how you do this Which among the following is not a way of heat transfer in the environment?1. Conduction2. Convection3.Radiation4. Diffraction If a population of a town is recorded at 1,200 in the year 2000 and the population increases by exactly 50 people each year, what will be the population of the town in 2018? Be careful to treat the year 2000 as the beginning; let x be the number of years since the year 2000.The answer is not 2,100 Which behavior is most likely to lead to the development of a chronic disease? If an economy were experiencing a high rate of unemployment as the result of weak aggregate demand, a Keynesian economist would be most likely to recommend a. a reduction in taxes, without any offsetting reduction in government expenditures. b. maintenance of a balanced budget. c. a reduction in taxes coupled with a reduction in government expenditures of equal size. d. an increase in government expenditures coupled with an increase in taxes of equal size. What is a characteristic of total body fat?O It includes stored fat in body tissue.OIt includes essential fats harmful for cell function.O It can be used to determine a person's body weight.O It can be used to determine body mass percentage.ANSWERR Anouk is extremely dedicated to his family and friends, often putting their needs above his own. For example, Anouk recently spent time consoling a friend instead of studying for his chemistry midterm. Because of this, he received a bad grade on the exam. Which personality quality best describes Anouk Anita thinks that she has heterozygous alleles for red hair. if she is correct, which of these diagrams best illustrates anitas alleles for red hair? 2 chromosomes are labeled upper r and upper r. 2 chromosomes are labeled upper r and r. one chromosome is labeled upper r and another is unlabeled. 2 chromosomes are labeled r and r. how did the nazi soviet pact help advance An effective topic outline is? how can one establish whether a liquid sample extracted from a plant is pure sarah decided go drink less juice. she read current dietary guidelines about daily water intake. which steps in making smart food choices did sarah follow? select three options Which of the following could result in secondary succession?the formation of a tall sand dune on a previously grassy beacha vast glacier in motion forming a U-shaped valley in its wakea volcanic eruption that covers most of what used to be a forestan introduced species that destroys all the native plants in an area. The answer is D. An introduced species that destroys all the native plants in an area. what is the area of stuvwx in the parallelogram below? Select the correct answer. If the factors of quadratic function g are (x 7) and (x + 3), what are the zeros of function g? A. -7 and 3 B. -7 and -3 C. -3 and 7 D. 3 and 7 what methods could you use to set up printing in an organization?