Link to home
Start Free TrialLog in
Avatar of STEVE00098
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
Avatar of Mick Barry
Mick Barry
Flag of Australia image

String[] array = s.split(";");
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of STEVE00098
STEVE00098

ASKER

what would be the class name and method name?
for what exactly?
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(array));   // convert array back to string to display output

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
I ran javac it compiled w/o any issues. How to create a jar file out of this,
Thank you so much forthe help. Great man..keep up the good work
jar cvf  stringtoarray.jar steve.class