From 18586153cdaf7bcd19d8c105409ef39d190e7cb6 Mon Sep 17 00:00:00 2001 From: rwygmans <68482511+rwygmans@users.noreply.github.com> Date: Sat, 9 Aug 2025 18:46:16 -0400 Subject: [PATCH 1/3] Add remove operation documentation for Java queue --- .../concepts/queue/terms/remove/remove.md | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 content/java/concepts/queue/terms/remove/remove.md diff --git a/content/java/concepts/queue/terms/remove/remove.md b/content/java/concepts/queue/terms/remove/remove.md new file mode 100644 index 00000000000..1805007c9db --- /dev/null +++ b/content/java/concepts/queue/terms/remove/remove.md @@ -0,0 +1,44 @@ +--- +Title: 'The Title' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed +Description: 'A brief description.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) +Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! + - 'A subject name' + - 'A second subject name' + - 'An nth subject name' +Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! + - 'A tag' + - 'A second tag' + - 'An nth tag' +CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first + - 'learn-example-course' + - 'paths/example-path' +--- + +[A brief definition - make sure first mention of term is in **bold**.] + +## Syntax + +[Text, code, images, parameters, etc. about the syntax] + +## Example + +[Text, code, images, etc. about example 1] + +## Codebyte Example (if applicable) + +We can currently support: + +- Python +- JavaScript +- Ruby +- C++ +- C# +- Go +- PHP + +See [content-standards.md](https://github.com/Codecademy/docs/blob/main/documentation/content-standards.md) for more details! + +```codebyte/js +# Example runnable code block. +console.log('Hello, World!'); +``` \ No newline at end of file From 727e145e55844a17fc99b29f1b0eebdd2a3207d8 Mon Sep 17 00:00:00 2001 From: rwygmans <68482511+rwygmans@users.noreply.github.com> Date: Sat, 9 Aug 2025 19:02:53 -0400 Subject: [PATCH 2/3] Add Java Queue .remove() term: description, syntax, example --- .../concepts/queue/terms/remove/remove.md | 74 +++++++++++-------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/content/java/concepts/queue/terms/remove/remove.md b/content/java/concepts/queue/terms/remove/remove.md index 1805007c9db..4189ff5ea95 100644 --- a/content/java/concepts/queue/terms/remove/remove.md +++ b/content/java/concepts/queue/terms/remove/remove.md @@ -1,44 +1,60 @@ --- -Title: 'The Title' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed -Description: 'A brief description.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) -Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! - - 'A subject name' - - 'A second subject name' - - 'An nth subject name' -Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! - - 'A tag' - - 'A second tag' - - 'An nth tag' -CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first - - 'learn-example-course' - - 'paths/example-path' +Title: '.remove()' +Description: 'Removes and returns the head of the queue; throws an exception if the queue is empty.' +Subjects: + - 'Code Foundations' + - 'Computer Science' +Tags: + - 'Queues' + - 'Collections' + - 'Methods' +CatalogContent: + - 'learn-java' + - 'paths/computer-science' --- -[A brief definition - make sure first mention of term is in **bold**.] +The [`Queue`](https://www.codecademy.com/resources/docs/java/queue) interface's **`.remove()`** method removes and returns the element at the head (front) of the queue. If the queue is empty, it throws a `NoSuchElementException`. ## Syntax -[Text, code, images, parameters, etc. about the syntax] +```pseudo +queue.remove() +``` + +- **Receiver**: `queue` is an instance of `Queue` from `java.util`. +- **Returns**: `E` — the head element. +- **Throws**: `NoSuchElementException` if the queue is empty. + +Note: Do not confuse this with `remove(Object o)`, which is inherited from `Collection` and removes a single matching element from the queue if present. ## Example -[Text, code, images, etc. about example 1] +The example below uses a `LinkedList` implementation to demonstrate `.remove()` returning and deleting the head element: + +```java +import java.util.Queue; +import java.util.LinkedList; -## Codebyte Example (if applicable) +public class RemoveExample { + public static void main(String[] args) { + Queue queue = new LinkedList<>(); + queue.offer("Alice"); + queue.offer("Bob"); + queue.offer("Charlie"); -We can currently support: + System.out.println("Queue before remove: " + queue); -- Python -- JavaScript -- Ruby -- C++ -- C# -- Go -- PHP + String head = queue.remove(); // removes and returns "Alice" + System.out.println("Removed head: " + head); + System.out.println("Queue after remove: " + queue); + } +} +``` -See [content-standards.md](https://github.com/Codecademy/docs/blob/main/documentation/content-standards.md) for more details! +This results in the following output: -```codebyte/js -# Example runnable code block. -console.log('Hello, World!'); +```shell +Queue before remove: [Alice, Bob, Charlie] +Removed head: Alice +Queue after remove: [Bob, Charlie] ``` \ No newline at end of file From 45eb21b481f9dca9a97c6337817b5dc2423b944d Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Wed, 13 Aug 2025 13:30:39 +0530 Subject: [PATCH 3/3] Update remove.md --- .../concepts/queue/terms/remove/remove.md | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/content/java/concepts/queue/terms/remove/remove.md b/content/java/concepts/queue/terms/remove/remove.md index 4189ff5ea95..de2d688f82d 100644 --- a/content/java/concepts/queue/terms/remove/remove.md +++ b/content/java/concepts/queue/terms/remove/remove.md @@ -1,19 +1,19 @@ --- -Title: '.remove()' -Description: 'Removes and returns the head of the queue; throws an exception if the queue is empty.' +Title: 'remove()' +Description: 'Removes and returns the head (first element) of the queue, throwing an exception if the queue is empty.' Subjects: - 'Code Foundations' - 'Computer Science' Tags: - - 'Queues' - 'Collections' - 'Methods' + - 'Queues' CatalogContent: - 'learn-java' - 'paths/computer-science' --- -The [`Queue`](https://www.codecademy.com/resources/docs/java/queue) interface's **`.remove()`** method removes and returns the element at the head (front) of the queue. If the queue is empty, it throws a `NoSuchElementException`. +Java's [`Queue`](https://www.codecademy.com/resources/docs/java/queue) interface's **`remove()`** method removes and returns the element at the head (front) of the queue. If the queue is empty, it throws a `NoSuchElementException`. ## Syntax @@ -21,15 +21,23 @@ The [`Queue`](https://www.codecademy.com/resources/docs/java/queue) interface's queue.remove() ``` -- **Receiver**: `queue` is an instance of `Queue` from `java.util`. -- **Returns**: `E` — the head element. -- **Throws**: `NoSuchElementException` if the queue is empty. +**Parameters:** + +The `remove()` method does not take any parameters. + +**Return value:** -Note: Do not confuse this with `remove(Object o)`, which is inherited from `Collection` and removes a single matching element from the queue if present. +Returns the element removed from the head of the queue. -## Example +**Exception:** -The example below uses a `LinkedList` implementation to demonstrate `.remove()` returning and deleting the head element: +Throws `NoSuchElementException` exception if the queue is empty. + +> **Note:** Don’t confuse `remove()` with `remove(Object o)`, which is inherited from `Collection` and removes the first matching element from the queue if it exists. + +## Example: Removing the Head Element Using Java Queue remove() + +The example here uses a `LinkedList` implementation to demonstrate `.remove()` returning and deleting the head element: ```java import java.util.Queue; @@ -57,4 +65,4 @@ This results in the following output: Queue before remove: [Alice, Bob, Charlie] Removed head: Alice Queue after remove: [Bob, Charlie] -``` \ No newline at end of file +```