Use Java Write a method called remove that accepts one ArrayList parameter and o
ID: 3800985 • Letter: U
Question
Use Java Write a method called remove that accepts one ArrayList parameter and one char parameter. Go through the ArrayList and remove any String that begins with the character in the second parameter. The method does not need to return any values. //Define your method here:Use Java Write a method called remove that accepts one ArrayList parameter and one char parameter. Go through the ArrayList and remove any String that begins with the character in the second parameter. The method does not need to return any values. //Define your method here:
Write a method called remove that accepts one ArrayList parameter and one char parameter. Go through the ArrayList and remove any String that begins with the character in the second parameter. The method does not need to return any values. //Define your method here:
Explanation / Answer
Class RemoveChr{
List<Character> char= new ArrayList<>();
char.add('a');
char.add('p');
char.add('e');
char.add('x');
char.remove(Character.valueOf('p'));//to remove specified character
// to remove a character based on particular index/position
String st="apex";
StringBuilder builder = new StringBuilder(st);
//to remove 2nd character from the array list
builder.deleteCharAt(1);//since index starts at 0
system.out.println("enter the charater to be deleted:");
System.out.println("input string:"+st);
system.out.println("string after removing character :"+builder.toString);
}
output:
enter the charater to be deleted: p
input string: apex
string after removing character:aex
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.