HOME
> System software
> Java: Splitting A String - How To Do It
Java: Splitting a string - how to do it
Since a string is a string of characters, a string variable can sometimes be very long. If you have created a string variable in Java and only need a subset of it, it can therefore be useful to split a string.
Splitting: How strings are used in Java
A string is a type of variable that is used not only in Java, but also in other programming languages. In this context, a string variable consists of a string of characters that can contain a sequence of letters, digits or special characters and is enclosed in execution characters. To declare a new string variable in Java, you must first generate a new string variable using the "String name" command and then assign a range of values to it using "name =". The placeholder "name" is replaced by the name you want the string variable to have.How to split a string variable in Java
Once you have created a string variable, Java gives you several methods to split it. If you want Java to output only a subset of the string, you can do this with the "substring()" function.- In addition, splitting a string variable into multiple subsets is also possible using the split function.
- Geben Sie hierfür einfach den Code „public String [] split („String“ regex)“ in Java ein und ersetzen Sie den Platzhalter „String“ durch den Namen Ihrer Stringvariable.
- Zudem können Sie bei der Eingabe des Befehls spezifizieren, an welcher Stelle der String geteilt werden soll.