#1: Java Program to Remove all occurrences of a string 

  1. package com.instanceofjava;
  2.  
  3. class RemoveCharString{
  4.  
  5. public static void main(String [] args){ 

  6.   String str = "Java";
  7.     str = str.replace("a", "");
  8.     System.out.println(str);
  9. }
  10. }
Output:
  1. Jv

#2: Java Program to Replace First occurance of Specific index char in a String

  1. package com.instanceofjava;
  2.  
  3. class RemoveCharString{
  4.  
  5. public static void main(String [] args){ 

  6.   String str = "Java";
  7.  
  8. //String result = str.substring(0, index) + str.substring(index+1);
  9.  
  10.   String result = str.substring(0, 1) + str.substring(1+1);
  11.   System.out.println(result);
  12.  
  13. }
  14. }


Output:
  1. Jva


#3: Java Program to Remove all Numbers from a string.

  1. package com.instanceofjava;
  2.  
  3. class RemoveNumberString{
  4.  
  5. public static void main(String [] args){ 

  6.   String str = "Instance12ofjava143";
  7.   str = str.replaceAll("[0-9]","")
  8.   System.out.println(str);
  9.  
  10. }
  11. }
Output:
  1. Instanceofjava

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu