Solved

String to String array

Posted on 2011-03-18
10
461 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

628 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