Write a method that given a non-empty ArrayList of Integers parameterand also an Integer parameter, the method returns a new ArrayList containing the elements from the original ArrayList that come after the first occurrence of Integer parameter in the original ArrayList.
If the original ArrayList does not contain an occurrence of the Integer parameter return an empty ArrayList . The original ArrayList must be unaffected by the method execution.
Following are some examples of the invocation of the method using explicit parameters, with an ArrayList represented by a bracketed list. The returned ArrayList follows the '→' character.
postList({1, 2, 4, 1}, 4); → {1}
postList({3, 1, 4}, 3); → {1, 4}
postList({1, 4, 4}, 4); → {4}
postList({1, 2, 4, 1}, 5); → {}import java.util.ArrayList;
import java.util.List;
public class ArrayListEx {
public static void main(String[] args) {
ArrayList<Integer> list = new
ArrayList<>();
list.add(3);
list.add(1);
list.add(4);
list.add(5);
System.out.println(postList(list, 3));
}
private static List
postList(ArrayList<Integer> l, int n) {
ArrayList<Integer> list = new
ArrayList<>();
boolean flag = false;
for (int x : l) {
if (x == n)
{
flag = true;
continue;
}
if (flag)
list.add(x);
}
return list;
}
}
![LITTITULLU TUyLISLL [1, 4, 5]](http://img.homeworklib.com/questions/cf883cc0-302f-11eb-988a-9b101e28a364.png?x-oss-process=image/resize,w_560)
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Write a method that given a non-empty ArrayList of Integers parameterand also an Integer parameter, the...
A java exercise please!
Write a static method named swapHavles that takes an ArrayList of integers as a a parameter and returns a new ArrayList that has every element in the second half of the original ArrayList swapped with every element in the first half of the original ArrayList. Note: • You can assume that the ArrayList passed to this method as a parameter always contains an even number of elements and will always contain at least two elements. For...
Write a method that takes an ArrayList of Integer objects and returns an ArrayList of Character objects of the same size. The returned elements of the ArrayList are assigned letter grade corresponding to integer grade of the same index element of the ArrayList parameter (A if 90 or above, F if less than 60). Include code to test your method. [For other letter grades: 80 ?? 89 −> ?, 70 ?? 79 −> ?, 60 ?? 69 −> ?]
java code level: beginner write a method sumList() public static Integer sumList(ArrayList<Integer> list) This method calculates the sum of all Integer values in a given ArrayList. For example, if ArrayList<Integer> list contains {1, 2, 3}, a call to sumList(list) should return 1+2+3, which is 6 as an Integer. Return null if the list is empty or null. Think about the base case. When should the method terminate/end? Under what condition should your method stop making recursive calls and return your...
//Java (Sort ArrayList) Write the following method that sorts an ArrayList: public static > void sort(ArrayList list) Write a test program that does the following operations: 4. Creates an empty ArrayList of Integer elements; 5. Generates 20 integer values, drawn at random between 0 and 9 (included), and adds them to the array list; 6. Calls the method sort and prints both the original list, and the sorted one.
Write a method maxOccurrences that accepts a list of integers as a parameter and returns the number of times the most frequently occurring integer (the “mode”) occurs in the list. Solve this problem using a map as auxiliary storage. If the list is empty, return 0.
Write a method called stutter that accepts an ArrayList of strings and an integer k as parameters and that replaces every string with k copies of that string. For example, if the list stores the values ["how", "are", "you?"] before the method is called and k is 4, it should store the values ["how", "how", "how", "how", "are", "are", "are", "are", "you?", "you?", "you?", "you?"] after the method finishes executing. If k is 0 or negative, the list should be...
iii.print out the arraylist iv.reverse all the elements v.print
out this arraylist vi.make a clone of the arraylist
vii.remove all the elements at any odd index of the original
arraylist (not the cloned one)
viii.print out the original arraylist ix.reverse the cloned
arraylist x.print out the cloned arraylist (this arraylist should
still contain the original sequence of elements in order)
xi.merge the cloned arraylist to the original arraylist (please
think about what happens and draw a diagram for yourself to...
Write a method called reverseFirstK that accepts an integer k and a queue of integers as parameters and reverses the order of the first k elements of the queue, leaving the other elements in the same relative order. For example, if a queue named q stores [10, 20 30, 40, 50, 60, 70, 80, 90], the call of reverseFirstK (4, q):should change the queue to store [40, 30 20, 10, 50, 60, 70, 80, 90]. If k is 0 or...
I need java code for the following problem.
Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...
Write a method public static ArrayList merge(ArrayList a, ArrayList b) that merges two array lists, alternating elements from both array lists. If one array list is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer array list. For example, if a is 1 4 9 16 and b is 9 7 4 9 11 then merge returns the array list 1 9 4 7 9 4 16 9 11...