-2

public static String RemoveSpace(String s){ String str="";

  for(int i=0;i<s.length();i++)
     if(s.charAt(i)!=32)
        str+=s.charAt(i);
    
  return str.toLowerCase();

2 Answers2

0

A char is just a number - a numeric type with two bytes. It's often written inside '' marks, but it can be used interchangeably with other numbers. In particular, the value of ' ' (space) is 32, when considered as a number. So when you compare a char with 32, you're just comparing it to ' ', even though 32 is technically four bytes, not just two.

Your code example just appends characters to str whenever they are NOT the same as 32, in other words, when they're not spaces.

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
0

https://www.techonthenet.com/ascii/chart.php

In the ASCII table 32 stands for Space.