STEVE00098
asked on
String to String array
Hello,
I am stuck, please help. I am looking for a simple java program that can convert string to string array and also want to know how to pass the string parameter to java program and return a string array from other java application.
For example the input parameter will be string like 1;2;3;4;5 , return a string array 1,2,3,4,5
Thank you all
I am stuck, please help. I am looking for a simple java program that can convert string to string array and also want to know how to pass the string parameter to java program and return a string array from other java application.
For example the input parameter will be string like 1;2;3;4;5 , return a string array 1,2,3,4,5
Thank you all
String[] array = s.split(";");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what would be the class name and method name?
for what exactly?
ASKER
I mean, could you please give an example of how to call this from other application and i think we need to create a jar file. In order to make use of the example you provided don't i need to put the method you provided in a class and make a jar file.
public class Steve {
public static String[] toArray(String s) {
String[] array = s.split(";");
return array;
}
}
you can call it from another class using:
String s = "1;2;3;4;5";
String[] array = Steve.toArray(s);
System.out.println(Arrays. toString(a rray)); // convert array back to string to display output
public static String[] toArray(String s) {
String[] array = s.split(";");
return array;
}
}
you can call it from another class using:
String s = "1;2;3;4;5";
String[] array = Steve.toArray(s);
System.out.println(Arrays.
ASKER
Thanks so much for the prompt reply. Do I need to import java.util.* to make it work or are we good w/o importing packages
ASKER
I ran javac it compiled w/o any issues. How to create a jar file out of this,
ASKER
Thank you so much forthe help. Great man..keep up the good work
jar cvf stringtoarray.jar steve.class
jar cvf stringtoarray.jar steve.class