In: Computer Science
Java
1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that removes all of the strings of even length from the list.
2. Given the following Vehicle interface and client program in the Car class:
public interface Vehicle{
public void move();
}
public class Car implements Vehicle{
public static void main(String args[])
Vehicle v = new Vehicle(); // vehicle declaration
}
The above declaration is valid? True or False?
3. Java permits a class to implement only one interface? True or false
4. The Comparable interface enables the comparison of objects in Java? True or false
Answer 1:
import java.util.ArrayList;
public class TestRemoveEvenLength {
public static void main(String[] args) {
ArrayList<String>list = new ArrayList<>();
list.add("Uday");
list.add("Remove");
list.add("ABC");
list.add("Test");
list.add("Testw");
System.out.println(list);
removeEvenLength(list);
System.out.println(list);
}
private static void removeEvenLength(ArrayList<String> list) {
ArrayList<String>res = new ArrayList<>();
for(String x:list) {
if(x.length() % 2 == 0)
res.add(x);
}
list.removeAll(res);
}
}
Answer 2:
The above declaration is valid? False
as we missed overriding the move in Car
Java permits a class to implement only one interface? false
we can implement any number of interface
The Comparable interface enables the comparison of objects in
Java?
True
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME
IT IS VERY IMP FOR ME