Replace text with replaceAll(). Learn the syntax using an editable java example.
When to use it
Use this technique in input parsing, formatting and text processing. Check the input types, any required imports, and whether the operation changes existing values or produces a new result.
Syntax
class Main { public static void main(String[] a) { System.out.println("a12b".replaceAll("[0-9]+", "-")); } }Parameters
Inspect the literals, variables and function arguments used in the example. Replace values with compatible java types before testing.
Returns / effect
Expected demonstration result: a-b.
Expected output
a-b
Common mistake and fix
Watch for empty input, encoding differences and special characters.
Good practices
Keep the example small, check its documented output, then adapt it to your own project with validation and error handling.
Practice exercise
Try changing one input in the replace text with replaceall() example. Predict how the output changes, then compare with the reference output.
Compatibility: Confirm support in your installed language/runtime version; some examples need modern standard libraries.
Related concepts: strings, examples, syntax
Explain this code
Try a small exercise
Try changing one input in the replace text with replaceall() example. Predict how the output changes, then compare with the reference output.
Show a hint
Change a single literal or input first; compare the result before making more edits.
Show example solution
class Main { public static void main(String[] a) { System.out.println("a12b".replaceAll("[0-9]+", "-")); } }Open permanent reference page ↗
Educational examples are not a substitute for a real compiler or version-specific documentation. JavaScript, Python and SQLite demos run in isolated browser contexts when supported; Python and SQL load an online WebAssembly runtime on first use. Other languages receive structural hints, not compiler validation. No visitor code executes on WordPress.