Splitting a string between letters and digits

0 votes

I have the following String:

String str = "123abc345def";

Now want to divide the above String as shown below, but somehow I am unable to perform this.

s[0] = "123";
s[1] = "abc";
s[2] = "345";
s[3] = "def";

Please help me out of these. Thanks in advance.

Oct 25, 2018 in Java by v.liyyah
• 1,300 points
63 views

1 answer to this question.

0 votes

Maybe you can try splitting the String with (?<=\D)(?=\d)|(?<=\d)(?=\D).

You can use it as:

str.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");

This will compare the positions between a number and NaN be it any order and split the String accordingly.

answered Oct 25, 2018 by code.reaper12
• 3,450 points

Related Questions In Java

0 votes
1 answer

Difference between String.equals() and ==

Though both are used for comparison, but the ...READ MORE

answered May 7, 2018 in Java by geek.erkami
• 2,320 points
28 views
0 votes
1 answer
0 votes
2 answers

How to check if a string has only letters

You could probably use Java 8 lambda ...READ MORE

answered Aug 30 in Java by Karan
• 1,780 points
36 views
0 votes
1 answer

What's the difference between @JoinColumn and mappedBy when using a JPA @OneToMany association?

The annotation @JoinColumn indicates that this entity is the owner of ...READ MORE

answered Oct 18, 2018 in Java by Sushmita
• 6,880 points
2,439 views
0 votes
3 answers

Check if a String is numeric in Java

Java 8 Lambda Expression is used: String someString ...READ MORE

answered Sep 3, 2018 in Java by Daisy
• 8,050 points
663 views
0 votes
2 answers

Generate an alpha-numeric string randomly

Java supplies a way of doing this ...READ MORE

answered Jul 18, 2018 in Java by Daisy
• 8,050 points
184 views
0 votes
1 answer

How do I create a Java string from the contents of a file?

If you're looking for an alternative that ...READ MORE

answered Apr 19, 2018 in Java by Rishabh
• 3,540 points
90 views
0 votes
2 answers

Counting no of Occurrence of a particular character inside a string in Java

We can find out the no. of ...READ MORE

answered Sep 7, 2018 in Java by Sushmita
• 6,880 points
245 views
0 votes
1 answer

How to remove ‘char’ from a String?

Hi...here you can try using the overloaded ...READ MORE

answered May 21, 2018 in Java by code.reaper12
• 3,450 points
29 views
0 votes
1 answer

Purpose of “String args[]” in the “psvm” of Java

Let me give you the complete explanation ...READ MORE

answered May 7, 2018 in Java by code.reaper12
• 3,450 points
85 views