Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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