Trusted by Students Everywhere
Why Choose Us?
0% AI Guarantee
Human-written only.
24/7 Support
Anytime, anywhere.
Plagiarism Free
100% Original.
Expert Tutors
Masters & PhDs.
100% Confidential
Your privacy matters.
On-Time Delivery
Never miss a deadline.
1) Which of these method implementations would correctly insert an element into an ArrayList before every even index? public void addEven(ArrayList<E> array, E element) { for(int index = 1; index < array
1) Which of these method implementations would correctly insert an element into an ArrayList before every even index?
public void addEven(ArrayList<E> array, E element)
{
for(int index = 1; index < array.size(); index++)
{
if(index %2 == 0)
{
array.add(index+ 1, element);
index--;
}
}
}
public void addEven(ArrayList<E> array, E element)
{
for(int index = 0; index < array.size(); index++)
{
if(index %2 == 0)
{
array.add(index, element);
index++;
}
}
}
public void addEven(ArrayList<E> array, E element)
{
for(int index = 0; index < array.size(); index++)
{
if(index %2 == 0)
{
array.add(index -1, element);
index++;
}
}
}
public void addEven(ArrayList<E> array, E element)
{
for(int index = 0; index < array.size(); index++)
{
if(index %2 == 0)
{
array.add(index, element);
index++;
index++;
}
}
}
2. Which of these methods will properly traverse two ArrayLists and print any index that have the same value in both ArrayLists?
public void printSharedValues(ArrayList<Integer> array1, ArrayList<Integer> array2)
{
int size;
if(array1.size() > array2.size())
{
size = array2.size();
}
else
{
size = array1.size();
}
while(index < size)
{
int index = 0;
if(array1.get(index) == array2.get(index))
{
System.out.println(index);
}
index++;
}
}
public void printSharedValues(ArrayList<Integer> array1, ArrayList<Integer> array2)
{
int index = 0;
while(index < array1.size())
{
if(array1.get(index) == array2.get(index))
{
System.out.println(index);
}
index--;
}
}
public void printSharedValues(ArrayList<Integer> array1, ArrayList<Integer> array2)
{
int index = 0;
int size;
if(array1.size() > array2.size())
{
size = array2.size();
}
else
{
size = array1.size();
}
while(index < size)
{
if(array1.get(index) == array2.get(index))
{
System.out.println(index);
}
index++;
}
}
public void printSharedValues(ArrayList<Integer> array1, ArrayList<Integer> array2)
{
int index = 0;
while(index < array1.size())
{
if(array1.get(index) == array2.get(index))
{
System.out.println(index);
}
index++;
}
}
Expert Solution
For detailed step-by-step solution, place custom order now.
Need this Answer?
This solution is not in the archive yet. Hire an expert to solve it for you.
Get a Quote





