Solved

String to String array

Posted on 2011-03-18
10
451 Views
Last Modified: 2012-06-27
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
Comment
Question by:STEVE00098
  • 5
  • 5
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 35169662
String[] array = s.split(";");
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 35169672
public String[] toArray(String s) {
   String[] array = s.split(";");
   return array;
}
0
 

Author Comment

by:STEVE00098
ID: 35169904
what would be the class name and method name?
0
 
LVL 92

Expert Comment

by:objects
ID: 35169906
for what exactly?
0
 

Author Comment

by:STEVE00098
ID: 35169927
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 92

Expert Comment

by:objects
ID: 35169936
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
 

Author Comment

by:STEVE00098
ID: 35169955
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
 

Author Comment

by:STEVE00098
ID: 35169967
I ran javac it compiled w/o any issues. How to create a jar file out of this,
0
 
LVL 92

Expert Comment

by:objects
ID: 35169969
0
 

Author Comment

by:STEVE00098
ID: 35169977
Thank you so much forthe help. Great man..keep up the good work
jar cvf  stringtoarray.jar steve.class
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now