• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 471
  • Last Modified:

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
0
STEVE00098
Asked:
STEVE00098
  • 5
  • 5
1 Solution
 
objectsCommented:
String[] array = s.split(";");
0
 
objectsCommented:
public String[] toArray(String s) {
   String[] array = s.split(";");
   return array;
}
0
 
STEVE00098Author Commented:
what would be the class name and method name?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
objectsCommented:
for what exactly?
0
 
STEVE00098Author Commented:
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.

0
 
objectsCommented:
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

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

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now