How to Remove String Character

Problem deleting String character:

public class Main {
  public static void main(String[] args) {
    String myStr = "Hello";
    System.out.println(myStr.replace('l', ''));

Returns Following error error: empty character literal
    System.out.println(myStr.replace('l', ''));
1 error

Use " instead of ’
String literals can be empty.

1 Like

To add to what CSharpIsGud is saying, you can’t have an empty char, it doesn’t make sense really. No character is not an actual character, but for a string which can be an arbitrary length it works.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.