Hi Everybody in comp.lang.java, again!!!
I'm quite new here so please Nuno let me first introduce myself, short...
My name is Piotr (Peter in Eglish), but I'm often using "piotr" in my
signature, to express my growing (not grown yet) experience in the
Computer Science... :-)
I am from Poland and I'm (rather occasional) a reader of this group
since last a few months.
I've been working for 10 years writing software mostly for OS/400
based machines, so my experience is divided into many different
programming techniques and technologies including Java (this one for
about six years).
Last a couple of months I'm also a quite active writer for the "Polish
version" of this group (pl.comp.lang.java) where everyone understanding
our language is welcome also...
I can't make a promise for writing here, but I hope nobody will be
offended with me for my possible future posts here.
And hope everybody forgive my non-perfect English... this is not my
native language... :)
Here is also my personal greetings exchanged with all of the reputable
members of this group...
OK, Nuno..., lets back to your problem... I've decided not to answer you
personally because I think You should express a little more precisely
Your questions, and probably most of the people writing here, have no so
much time (I guess...) to talk to you on details of your question, so do
I...
My answer:
Use the following as an example for your TestFile.main method body:
public static void main(String[] args) {
....
Stack stack = ... // instantiate your Stack here
for(int i = 0; i < args.length; ++i) {
String a = args[i]; // (i + 1)th argument
for(int ai = 0; ai < a.length(); ++ai) {
char c = a.charAt(ai); // (ai + 1)th character of a
// now you can add c into your stack...
// assuming your Stack is java.util.Stack...
//...you can do it this way:
stack.push(new Character(c));
}
// and here you can (optionally) do some separation...
//...of your arguments stream :) eg:
if ((i + 1) < args.length)
stack.push(new Character(' '));
}
....
}
Ohh, of course..., you have to consider using StringBuffer or more
"advanced" stack for your particular needs.
Pozdrawiam/Regards
piotr
Nuno Silva wrote:
I'm trying to read a string from the console like
java TestFile arg1 arg2 .....
and I want then to split arg1 into 'a','r','g','1', to insert into a Stack.
How do I do such conversion ?
response to nu************@yahoo.com