java - how to split the string and store it in array -
i have tried following example gives following out put output[]
. have pass string "1.0" function calculatepayout()
, want store 1 in s[0]
, 0 in s[1]
import java.util.arrays; public class aps { public void calculatepayout(string amount) { string[] s = amount.split("."); system.out.println("output"+arrays.tostring(s)); } public static void main(string args[]) { new aps().calculatepayout("1.0"); } }
method split()
accepts regular expression. character .
in regular expressions means "everything". split string .
have escape it, i.e. split("\\.")
. second slash needed because first 1 escapes dot regular expression, second escapes slash java compiler.
Comments
Post a Comment