-
String to int
Can anyone tell me what is wrong with this method?? It keeps asking for an array.
public int totalSeconds() {
String duration = "15:20";
String[] durationParts = duration.split(":");
int totalSeconds = (Integer.parse(duration[0]) * 60) + Integer.parse(duration[1]);
}
-
Re: String to int
Your array is named 'durationParts', not 'duration'.
kind regards,
Jos
-
Re: String to int
Hi, try this.........
int totalSeconds = (Integer.parseInt(durationParts[0]))*60 +Integer.parseInt(durationParts[1]);
it will work
-
Re: String to int
A great big thank you to both of you for answering my question. I really appreciate it. Thanks