Solved

String to String array

Posted on 2011-03-18
10
454 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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
 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 115
allswap challenge 6 98
ArrayIndexOutOfBoundException 9 81
Oracle SQL syntax check  without executing 6 54
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

773 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