FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
StackAnnotation/src/stack/MyStringStack.java at master · flchua/StackAnnotation · GitHub
flchua
/
StackAnnotation
Public
forked from
kenken64/StackAnnotation
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
StackAnnotation
/
src
/
stack
/
MyStringStack.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (45 loc) · 1.55 KB
Breadcrumbs
StackAnnotation
/
src
/
stack
/
MyStringStack.java
Copy path
File metadata and controls
50 lines (45 loc) · 1.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package
stack
;
import
java
.
util
.
NoSuchElementException
;
import
java
.
util
.
Vector
;
/**
* <p>A <strong>MyStringStack</strong> </p>
* is a class that implements a simple (LIFO) stack object. It makes use of the Vector {@link java.util.Vector}
* <p>It has four basic operations:
* <code>push()</code> to push an element onto the stack
* <code>pop()</code> to retrieve the last pushed element
* <code>isEmpty()</code> to verify whether the stack has no more elements
* <code>clear()</code> to empty the stack.
* </p>
* @author Swarnalatha Ashok
* @version 1.0 2008-07-16
* @since JDK 1.5
*/
public
class
MyStringStack
{
private
Vector
<
String
>
v
=
new
Vector
<
String
> ();
public
void
push
(
String
newElement
) {
if
(
newElement
!=
null
)
v
.
add
(
newElement
);
}
/**
* Returns a String object that was pushed the last on the stack.
* <p>This method always returns a valid String. </p>
* <p>If there is no element it throws a NoSuchElementException exception.</p>
*
* @return the String on top of the stack
* @throws NoSuchElementException if there are no elements on the stack
* @see String
*/
public
String
pop
()
throws
NoSuchElementException
{
//throw new NoSuchElementException();
String
result
=
v
.
lastElement
();
v
.
remove
(
result
);
System
.
out
.
println
(
"hello"
);
return
result
;
//return v.lastElement();
}
public
boolean
isEmpty
() {
return
v
.
isEmpty
();
}
public
void
clear
() {
v
=
new
Vector
<
String
> ();
}
}
Back
|
FazBrowse Home
|
New Git URL