Java: String split method - command simply explained
In this practical tip, we explain how you can easily split strings in Java.
Java: String split method - how it works
- First you have to define a string. You can do this with the command »String str =" 004-034556 ";«.
- Then use »String [] parts = str.split (" - ");« to define a new string array, which is the original string that is divided at "-".
- With the commands »String part1 = parts [0];« and »String part2 = parts [1];« you can now save the individual substrings.
- Tip: If you found programming fun, you can take a look at our Java programming guide, in which we teach you step by step how to program with Java.
In the next practical tip, we will explain how you can apply conditions and loops in Java in a targeted manner.