Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
java
This method gets an Arraylist of Integers and a number(Integer). It returns an Arraylist.
It removes any instance of the given number from the Arraylist.
Example:
romoveInst([1,1,2,3,1,4],1)
returns: [2,3,4]
romoveInst([3,4,3,3],4)
returns: [3,3,3]
public static ArrayList<Integer> removeInst(ArrayList<Integer> r,Integer n)
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int size = in.nextInt();
int n = in.nextInt();
ArrayList<Integer> list = new ArrayList<>();
for(int i=0; i < size; i++) {
list.add(in.nextInt());
}
System.out.println(removeInst(list, n));
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Explain the fundamental difference between an array and an arraylist.arrow_forwardclass ArrayStackException extends Exception { ArrayStackException(String m) { super(m); }} public class ArrayStack { private int s[] = new int[100]; private int top=0; public void push(int data) throws ArrayStackException { if (top>=s.length) throw new ArrayStackException("Push overflow: " + data); s[top]=data; top++; } public int pop() throws ArrayStackException { if (top<=0) throw new ArrayStackException("Pop underflow: "); int value = s[top-1]; top--; return value; } public int peek() { int value = s[top-1]; return value; } public void clear() { top=0; } public int size() { return top; } public void display() { System.out.print( "size =" +top + ": "); for(int i =0; i<top;i++) { System.out.print( s[i] + " "); } System.out.println( ); } public static void…arrow_forwardpublic static ArrayList findExactString(String s, ArrayList myArray) { return null; } // Use the above method, findExactString, as a helper method to implement addWithoutDuplication method. The addWithoutDuplication method has the following properties: 1- It takes two arguments, a string s and an ArrayList myArray of type string. 2- It returns an integer which represents the number of occurrences of the string s in myArray while attempting to add it. 3- If myArray is null, it returns -1 4- If adds the string s to the end of the ArrayList myArray if the string s is not already there. public static int addwithout Duplication(String s, ArrayList myArray) { return -1;arrow_forward
- in javaarrow_forwardIn Javaarrow_forwardJAVA complete a method that swaps the first and second half of an array of integers. For example, if the array contains the values 1 4 9 16 25 36then after calling the method, it should contain the values16 25 36 1 4 9If the array contains an odd number of elements, leave the middle element in place. For example, 1 4 9 16 25 36 45becomes25 36 45 16 1 4 9arrow_forward
- 5. How to find all the leaders in an integer array in java? An element is leader if it is greater than all the elements to its right side. And the rightmost element is always a leader. For example int the array {16, 17, 4, 3, 5, 2}, leaders are 17, 5 and 2..arrow_forwardJava Complete the method with explaining, thank you!arrow_forwardJAVA programming language i need to create an "addFront" method in the bottom of the code that adds an element at the front. [-1, -3, -5] A.add(-9) ===> [-9, -1, -3, -5]. Its all the way in the bottom, please help me. public class ourArray { //define an array of integers private int[] Ar; //Ar is a reference //declare private int capacity = 100; private int size = 0; private int increment = 10; //default constructor public ourArray() { Ar = new int[100]; capacity = 100; size = 0; increment = 10; } //Constructor that accepts the capacity (C). It creates an array of C integersm, sets capacity to C // Increment to 10 public ourArray(int C) { Ar = new int [C]; size = 0; capacity = C; increment = 10; } //Constructor that accepts two integers (c, i) c for capacity and i for increment public ourArray (int C, int I) { Ar = new int[C]; size = 0; capacity = C; increment = I; } //setter for Increment public void setincrement(int I) { increment = I; } //getter for size, capacity…arrow_forward
- public int[] selectionSort(int[] array) {for (int i = 0; i < array.length - 1; i++) {int min = array[i];int minIndex = i;for (int j = i + 1; j < array.length; j++) {if (min > array[j]) {min = array[j];minIndex = j;}}if (minIndex == i) {array[minIndex] = array[i];array[i] = min;}}return array;}arrow_forwardJAVA Chapter 9 Multidimensional Arrays and the ArrayList Class Write a value returning method that returns the sum of the elements in the last column of each row in a two-dimensional array of ints. Include code to test your method.arrow_forwardin java Create two arrays with same length n: - Array A with integer numbers that user will insert- Array B with random numbers from 0 to 100.- Find sum of both arrays,- Find maximum values of both array and compare them: .if maximum of 1 st is lower then maximum of 2nd array: print sums of both arrays.if maximum of 1st is greater then maximum of 2nd array print 2nd array (use println)otherwise print first array in reverse.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education