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
77julia77 [94]
2 years ago
14

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

Computers and Technology
1 answer:
Yanka [14]2 years ago
7 0

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);

  }

}

You might be interested in
Carly’s Catering provides meals for parties and special events. Write a program that prompts the user for the number of guests a
Savatey [412]

Answer:

Answered below

Explanation:

Scanner n = new Scanner(System.in);

System.out.print("Enter number of guests: ");

int numOfGuests = n.nextline();

double pricePerGuest = 35.0;

double totalAmount = numOfGuests * pricePerGuest;

String event = " ";

if ( numOfGuests >= 50){

event = "Large event";

}else{

event = "small event";

}

System.out.print(numOfGuests);

System.out.println(pricePerGuest);

System.out.println( totalAmount);

System.out.println(event);

6 0
3 years ago
L a s t. i achieve 15 of 15 question on brainly.
Veseljchak [2.6K]
The Control key on a computer keyboard is a key that is used by pressing it in combination with other keys, enabling other keys on the keyboard to perform secondary functions. It is generally labeled as Ctrl.
4 0
3 years ago
The _____________ controls the internal operations of the computer's hardware, manages all of the devices connected to the compu
Nitella [24]

Answer:

The System Software (Operating System)

Explanation:

Examples of Operating Systems are Windows, MAC and Linux, these software are the foundation of every PC and manages all computer's resources

6 0
3 years ago
a colleague shared an excel file with you, and you want to display a worksheet that is hidden in it. how can you do that?
Sonja [21]

The hidden worksheet can be made visible with the right click on any worksheet and select unhide.

<h3>What is a worksheet?</h3>

A worksheet in Microsoft Excel is the collection of the rows and column that has been used to organize data. The collection of worksheets is called workbook.

The hidden worksheets are not visible in the workbook, and if an individual wants to unhide the hidden worksheet, he must right-click on any worksheet and select unhide.

Learn more about worksheet, here:

brainly.com/question/1024247

#SPJ1

4 0
2 years ago
Hymter. Wants to workin The Energy career field with electrical energy
m_a_m_a [10]

Answer: what is the question

Explanation:

3 0
3 years ago
Other questions:
  • You are asked to install a device that will combine several connections to the Internet and provide the sum of the available net
    8·2 answers
  • What is basic statement made up of​
    10·2 answers
  • Write the definition of a function named alternator that receives no parameters and returns true the first time it is invoked, r
    12·1 answer
  • Which VPN protocol does not support using Password Authentication Protocol (PAP), Challenge Handshake Authentication Protocol (C
    14·1 answer
  • You are tasked with implementing a recursive function void distanceFrom(int key) on the IntList class (provided). The function w
    14·1 answer
  • Eric’s computer slows down when he open several computer programs. Why does this happen?
    15·2 answers
  • What is the central idea of the second section:
    14·1 answer
  • Why is failure an important part of life and the engineering design process?
    13·2 answers
  • What’s an input Device
    7·2 answers
  • One student will be stationed near you in a coffee shop. The other student will be located two miles away from your school. You
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!