# Stack & Queue

### Initialization

{% tabs %}
{% tab title="Stack" %}
```javascript
Stack<String> stack = new Stack<>(); 
```
{% endtab %}

{% tab title="Queue" %}
```java
Queue<String> queue = new LinkedList<>();
```
{% endtab %}
{% endtabs %}

### Useful methods

{% tabs %}
{% tab title="Stack" %}
```java
element = stack.push(element); // push one in, O(1)
element = stack.pop(); // pop one out, O(1)
element = stack.peek(); // see the top element, O(1)
stack.isEmpty(); // return true or false
l = stack.length();
```
{% endtab %}

{% tab title="Queue " %}
```java
q.offer(element);  // O(1), out of bound raise Exception
q.poll(); // O(1), out of bound raise Exception
l = q.size();

```
{% endtab %}
{% endtabs %}
