Languages
[Edit]
EN

Java - split string by hyphen sign (minus sign - ascii 45 code)

3 points
Created by:
Alicia-Lambert
580

In this article, we would like to show you how to split string by hyphen sign in Java.

Practical example:

public class Program {

    public static void main(String[] args) {

        String text = "some-example-text";
        String[] parts = text.split("-");

        System.out.println(parts[0]);  // some
        System.out.println(parts[1]);  // example
        System.out.println(parts[2]);  // text
    }
}

Output: 

some
example
text

 

Alternative titles

  1. Java - how to split string by hyphen sign (minus sign - ascii 45 code)
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - split string by hyphen sign

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join