Java Question:
Describe what is an ArrayList (API) in Java. Provide an example code segment to describe as well.
In Java is used to store dynamically sized collection of elements. Contrary to Arrays that are fixed in size, an ArrayList grows its size automatically when new elements are added to it.ArrayList is a part of collection framework and is present in java.util package.
===================================================================================
import java.util.ArrayList; public class Driver { public static void main(String[] args) { // Creating an ArrayList of String ArrayList<String> countries= new ArrayList<>(); // Unlike array where we can store only fixed number of elements // in array list we can keep on adding elements without the // need to resize the array // ArrayList supports dynamic arrays that can grow as needed countries.add("US"); countries.add("Brazil"); countries.add("England"); countries.add("China"); System.out.println(countries); // Adding an element at a particular index in an ArrayList countries.add(2, "France"); System.out.println(countries); } }
======================================================================
Java Question: Describe what is an ArrayList (API) in Java. Provide an example code segment to...
Java In your own custom ArrayList<E> class(do not use Java Array List API) use Array algorithm Write a static function called RemoveNullElements() without creating another array. that remove Null elements and shift all the rest of the elements to the left/front (small indexes) of the array without changing the size or length of the original array( this meant the front of the array will have all the not Null elements, and the other haft will be empty/Null. Please provide test...
Java Question 4 3 pts Briefly answer these questions about interfaces on an example code segment. • What is an interface? • How is extending a class different from implementing an interface?
Question 28 What is the size of groceryList after the code segment? ArrayList<String> groceryList; groceryList = new ArrayList<String>(); groceryList.add("Bread"); groceryList.add("Apples"); groceryList.add("Grape Jelly"); groceryList.add("Peanut Butter"); groceryList.set(1, "Frozen Pizza"); Group of answer choices 5 4 3 Error: index out of bounds
47. What is overriding? Describe using java code showing an example of overriding. 48. Does Java allow us to refine behavior in subclasses? If so, show Java code that demonstrates this property. 49. Does Java allow us to replace behavior in subclasses? If so, show Java code that demonstrates this property. 50. Can dynamic binding be used in C++? If so, show how this is accomplished. 51. Is there a cost to providing the dynamic binding capability? If so, describe...
*JAVA* Assume we already have an ArrayList of Integers called list. Write code that will add 1 to each element of the list. For example, if the list originally contained 2, 4, -3, then it should contain 3, 5, -2 after the lines of code execute. Just write the necessary lines of code (not a whole method or program). Assume we already created the ArrayList and filled it with Integers.
Consider the following Java method: public static ArrayList<Integer nums ArrayList<Integer values new ArrayList<Integer0; for(int i=10; i<30; i-i+3) if(i%) values.add(i); return values: What is returned after the method call nums()? a. [12] b. [13] c. [14] d. [15] e. [16] O Which of the following represents the final output of the code segment below? int k: int[]A; A new int[3]: fork-0; k<A.length;k++) A[k]-A.length-k; forſk-0; k<A.length-1; k++) A[k+1]-A[k) for(int i-0;i<A.length;i++) System.out.print(A[i]+" "); a. 222 O b. 333 c. 444 d. 555 O...
How do I write a java code that mimics charAt without using java API just primitives and no charAt to be used? I know it comes from primitives but I am confused on how to assemble the loops to derive my own charAt code
Consider the following code segment. ArrayList<String> towns = new ArrayList<String> (); towns.add("Baltimore"); towns.add("Bethesda"); towns.add("Wheaton"); towns.add("Greenbelt"); towns.add("Rockville"); for (int k = 1; k< towns.size(); k ++) System.out.print(towns.get(k) + " "); What is printed as a result of executing the code segment? Baltimore Bethesda Wheaton Greenbelt IndexOutOfBoundsException message Baltimore Bethesda Wheaton Greenbelt Rockville Bethesda Wheaton Greenbelt Rockville Refer to the doSomething method: public static void doSomething (ArrayList list, int i, intj) SomeType temp = list.get(i); list.set(i, list.get()); list.set(j, temp); Which best describes...
edhesive Term 2 - Unit 5 Week 4 19. Consider the following code segment: ArrayList<Light bulbs - new ArrayList<light> (3 bulbs.add(new Light() bulb, remove (0) bulbs.add(new Light () Light b new Light () bulbs.add(1, b); bulbs.add(new Light()); bulbs.remove(0); bulbs.add(new Light()); bulbs.remove (2); bulbs.add(new Light(); After running the code, what is the size of bulbs? h 3 d 5 20. An ArrayList can hold _ a. Only primitive types b. Both class and primitive types c Only class types d. Only...
42. When does an object become subject to garbage collection? Describe using a Java example (show code). 43. What is the main difficulty in users performing their own free storage management? 44. What language allows users to perform their own free storage management? 45. What is overloading? Describe using java code showing an example of overloading. 46. Why would we desire to overload functions? Describe using a Java example (show code).