Solved

String to String array

Posted on 2011-03-18
10
459 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
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!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 111
Java basic valueOf question 1 50
jmeter usage 4 64
Java array sort 10 63
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

739 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