#1: Java Program to Remove all occurrences of a string
- package com.instanceofjava;
-
- class RemoveCharString{
-
- public static void main(String [] args){
- String str = "Java";
- str = str.replace("a", "");
- System.out.println(str);
- }
- }
Output:
#2: Java Program to Replace First occurance of Specific index char in a String
- package com.instanceofjava;
-
- class RemoveCharString{
-
- public static void main(String [] args){
- String str = "Java";
-
- //String result = str.substring(0, index) + str.substring(index+1);
-
- String result = str.substring(0, 1) + str.substring(1+1);
- System.out.println(result);
-
- }
- }
Output:
#3: Java Program to Remove all Numbers from a string.
- package com.instanceofjava;
-
- class RemoveNumberString{
-
- public static void main(String [] args){
- String str = "Instance12ofjava143";
- str = str.replaceAll("[0-9]","")
- System.out.println(str);
-
- }
- }
Output: