Write a static method getCommonStrings(ArrayList list1, ArrayList list2) that returns a new instance of ArrayList containing all of the strings common to both list1 and list2.

What will be an ideal response?


```
public static ArrayList
getCommonStrings(ArrayList list1,
ArrayList list2){

ArrayList result = new ArrayList();
for(int i=0; i for(int j=0; j if(list1.get(i).equals(list2.get(j)))
result.add(list1.get(i));
}
}

// Remove the duplicates
for(int i=0; i int j = i+1;
while(j if(result.get(i) == result.get(j))
result.remove(j);
else
j++;
}
}

return result;
}
```

This code is in Methods.java. An alternate solution is also given.

Computer Science & Information Technology

You might also like to view...

A thin client

a. must operate on a high-performance device b. performs most of the application’s tasks c. relies on a server to perform most of the functions needed d. none of the above

Computer Science & Information Technology

You can enter different characters, such as placeholders, separators, literal characters, and colors, in the ________ of a field to create a custom format

Fill in the blank(s) with correct word

Computer Science & Information Technology

A(n) ____ is simply a section of a program that performs a specific task.

A. module B. constant C. argument D. parameter

Computer Science & Information Technology

A(n) _______ is a piece of software needed for printer operation and so that the operating system can control the printer

Fill in the blank(s) with correct word

Computer Science & Information Technology