Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
Active reading.
Source Link
Peter Mortensen

Here are two ways two achieve it.

WAY 1: As As you have to split two numbers by a special character you can use regex

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TrialClass
{
    public static void main(String[] args)
    {
        Pattern p=Patternp = Pattern.compile("[0-9]+");
        Matcher m=pm = p.matcher("004-034556");

        while(m.find())
        {
            System.out.println(m.group());
        }
    }
}

WAY 2:Using Using the string split method

public class TrialClass
{
    public static void main(String[] args)
    {
        String temp="004temp = "004-034556";
        String [] arrString=temparrString = temp.split("-"); 
        for(String splitString:arrString)
        {
            System.out.println(splitString);
        }
    }
}

Here are two ways two achieve it

WAY 1: As you have to split two numbers by a special character you can use regex

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TrialClass
{
    public static void main(String[] args)
    {
        Pattern p=Pattern.compile("[0-9]+");
        Matcher m=p.matcher("004-034556");

        while(m.find())
        {
            System.out.println(m.group());
        }
    }
}

WAY 2:Using string split method

public class TrialClass
{
    public static void main(String[] args)
    {
        String temp="004-034556";
        String [] arrString=temp.split("-"); 
        for(String splitString:arrString)
        {
            System.out.println(splitString);
        }
    }
}

Here are two ways two achieve it.

WAY 1: As you have to split two numbers by a special character you can use regex

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TrialClass
{
    public static void main(String[] args)
    {
        Pattern p = Pattern.compile("[0-9]+");
        Matcher m = p.matcher("004-034556");

        while(m.find())
        {
            System.out.println(m.group());
        }
    }
}

WAY 2: Using the string split method

public class TrialClass
{
    public static void main(String[] args)
    {
        String temp = "004-034556";
        String [] arrString = temp.split("-");
        for(String splitString:arrString)
        {
            System.out.println(splitString);
        }
    }
}
Source Link
Akshay Gaikwad

Here are two ways two achieve it

WAY 1: As you have to split two numbers by a special character you can use regex

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TrialClass
{
    public static void main(String[] args)
    {
        Pattern p=Pattern.compile("[0-9]+");
        Matcher m=p.matcher("004-034556");

        while(m.find())
        {
            System.out.println(m.group());
        }
    }
}

WAY 2:Using string split method

public class TrialClass
{
    public static void main(String[] args)
    {
        String temp="004-034556";
        String [] arrString=temp.split("-"); 
        for(String splitString:arrString)
        {
            System.out.println(splitString);
        }
    }
}
lang-java