how do you add strings(java)?

Semidevil

Diamond Member
Apr 26, 2002
3,017
0
76
so lets say I created a stack, and I want to add strings to them...how do I do that?


all I did so far is create the stack, like

Stack stack2 = new Stack();

so after I create my stacks what do I do in the next couple of lines?, how do I add strings to it?
 

TekChik

Senior member
Jan 15, 2003
839
0
0
so...just to clarify...

you're asking how to add strings to a stack?

:evil:

sorry...i couldnt resist :p
 

Gunslinger08

Lifer
Nov 18, 2001
13,234
2
81
stack2.push(string)

For some reason I can't remember if push is a stack or a queue thing.. I take it you didn't develop the classes for the stack yoursef, but instead you're using the included crappy ones in the java api?
 

Stack stack = new Stack();
stack.push("java");
stack.push("teh");
stack.push("at");
stack.push("suck");
stack.push("you");

while(!stack.empty()) System.out.print(stack.pop() + " ");
 

Gunslinger08

Lifer
Nov 18, 2001
13,234
2
81
Originally posted by: Ameesh
Originally posted by: Spamela
umm, stack2.addElement("RTFM")

lol, i believe the function is called push but that works

Yeah, it inherits addElement from vector, but I would just use push because it's more fun.