Answers for "remove character from array java"

5

Java remove character from string

// how to remove particular character from string
public class RemoveParticularCharacter
{
   public static void main(String[] args)
   {
      String strInput = "Hello world java";
      System.out.println(removeCharacter(strInput, 6));
   }
   public static String removeCharacter(String strRemove, int r)
   {
      return strRemove.substring(0, r) + strRemove.substring(r + 1);
   }
}
Posted by: Guest on December-07-2020
5

how to delete an element from an array in java

import java.util.Scanner;

public class ElemRemoval {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] intArr = {1, 2, 5, 12, 7, 3, 8};
        System.out.print("Enter Element to be deleted : ");
        int elem = in.nextInt();
        
        for(int i = 0; i < intArr.length; i++){
            if(intArr[i] == elem){
                // shifting elements
                for(int j = i; j < intArr.length - 1; j++){
                    intArr[j] = intArr[j+1];
                }
                break;
            }
        }
      
        System.out.println("Elements -- " );
        for(int i = 0; i < intArr.length - 1; i++){
            System.out.print(" " + intArr[i]);
        }                
    }
}
Posted by: Guest on April-29-2020

Code answers related to "remove character from array java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language