Replace Characters in Java: Explanation & Practice
Replace parts of a string
Problem summary
Replace all 'a' with '@' in 'Java'.
Starter code
public class Main {
public static void main(String[] args) {
String text = "Java";
// Replace and print
}
}Expected output and test cases
- Replace a with @
J@v@
Hints
- Use .replace(old, new) method
- Replaces all occurrences
- Returns a new string
Related Strings exercises
Practice all Strings exercises · Run this idea in the Java compiler