Page Contents
Interview Content
- C Programming Coding Questions
- C Pattern Programming Questions
- C Programming Interview Questions
- Java Programming Coding Questions
- Java Pattern Programming Questions
- Java Programming Interview Questions
- Python Programming Coding Questions
- Python Pattern Programming Questions
- Python Programming Interview Questions
- SQL Interview Questions
Program in Java to remove a specific character from string
Ans:
In this tutorial you will learn writing program for how to remove a character from a string in java.
Before start writing this program you should know how to work with String and character in Java.
Also Read This: C program to remove a character from String.
How this Java program will behave?
This program will take a String as an Input and also a character as an Input.
This input is a character that we want to remove from a given String.
For Example: I have given a String “Quescol” as an input and also a character ‘e’ as an input.
We will get Output as “Quscol”.
Function to remove character from String in Java
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.print("Please give a String : ");
String str= sc.nextLine();
Scanner sc1= new Scanner(System.in);
System.out.print("Please give a Char : ");
String ch= sc1.nextLine();
System.out.println(charToRemove(str, ch));
}
public static String charToRemove(String str, String ch){
return str.replace(ch," ");
}
}
Output:
Also prepare these Java Programs:
- Write a program in Java to print the Fibonacci series using iterative method.
- Palindrome program in Java using Iterative method
- Java program to find largest of three numbers
- Java program to sum the digits of a number using recursion
- Java program to swap two numbers using third variable
- Java Program to check if two strings are anagrams
- Java program to find largest and smallest number in an array
- Java Program to find top two maximum number in array
- Java Program to remove duplicate elements from an array
Latest Uploads on Website
- AVL Tree with explanation
- Radix sort algorithm explanation with example
- Quick Sort Algorithm with explanation
- Bubble sorting algorithm with Bubble sort program in C
- Insertion sort algorithm and program in C
- Selection Sort Algorithm and Program in C
- Linear probing technique explanation with example
- Collision in Hashing and Collision resolution technique
- Hashing in data structure with its types
- Binary search tree operations with Program
- Binary search tree in data structure
- Binary search algorithm in data structure with explanation
- linear search in data structure with Algo and Program