-3

Java- Extract part of a string between two similar special characters.

I want to substring the second number, example :

String str = '1-10-251';

I want the result to be: 10

sfmirtalebi
  • 370
  • 7
  • 16
  • 2
    Read up on the `split` method of the `String` class. – Dawood ibn Kareem Oct 13 '15 at 07:29
  • 1
    Possible duplicate of [How to extract a substring from a string in java](http://stackoverflow.com/questions/1265119/how-to-extract-a-substring-from-a-string-in-java) – Mani Deep Oct 13 '15 at 07:30
  • 1
    Possible duplicate of [Java- Extract part of a string between two special characters](http://stackoverflow.com/questions/4962176/java-extract-part-of-a-string-between-two-special-characters) – swidmann Oct 13 '15 at 07:44

1 Answers1

0
String str = "1-10-251";
String[] strArray = str.split("-");
System.out.println(strArray[1]);
Janath
  • 137
  • 9
  • Maybe consider to add some text to the code, to help future readers to learn even more from your answer :-) – LionC Oct 13 '15 at 08:11