Remove Spaces in a String


Code:

package sap;

public class RemoveSpaces {
   
    public static void main(String[] args){
       
        String str = "Hi nivetha";
        System.out.println("Input String: "+str);
        str = str.replaceAll("\\s", "");
       
        System.out.println("Output String: "+str);   
    }

}

Ouput:

Input String: Hi nivetha
Output String: Hinivetha

Comments

Popular posts from this blog

Rearrange Array in Maximum-Minimum form

Second Largest Element

Check if a number is a power of another number