If i would have a String array in java
Example
public static void main (String [] args)
{
int x = Integer.parseInt(args[2]);
}
What would be the equivalent of this code in clojure?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Clojure can call Java methods directly, so assuming your function is passed a String array you can just do:
Things to note:
agetis a function that gets an element from a Java array.(ClassName/methodName ...)is used to call a Java static method in ClojureIt’s also worth noting that Clojure can actually destructure Java arrays. So you could also do:
In this code,
s0takes the value of the first array element,s1the second,s2the third andmore-stringsis a sequence of any remaining arguments