Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/main/java/frc/robot/ArrayListExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
import java.util.List;
import java.util.function.Predicate;

/** Suppress Warnings. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this line is doing anything. But if it is, then it is suppressing all warnings, which we usually do not want to do. Remove this line and fix the warnings.

@java.lang.SuppressWarnings({"java:S106"})
public class ArrayListExample {
/**
* This is a main method.
*
* @param args is a String array
*/
public static void main(String[] args) {
List<String> programmingLanguages = new ArrayList<>();
programmingLanguages.add("C");
Expand All @@ -14,7 +20,7 @@ public static void main(String[] args) {
programmingLanguages.add("Kotlin");
programmingLanguages.add("Python");
programmingLanguages.add("Perl");
programmingLanguages.add("Ruby");
programmingLanguages.add("Callahan");

System.out.println("Initial List: " + programmingLanguages);

Expand All @@ -24,17 +30,17 @@ public static void main(String[] args) {

// Remove the first occurrence of the given element from the ArrayList
// (The remove() method returns false if the element does not exist in the ArrayList)
boolean isRemoved = programmingLanguages.remove("Kotlin");
System.out.println("After remove(\"Kotlin\"): " + programmingLanguages);

// Remove all the elements that exist in a given collection
List<String> scriptingLanguages = new ArrayList<>();
scriptingLanguages.add("Python");
scriptingLanguages.add("Ruby");
scriptingLanguages.add("Perl");
scriptingLanguages.add("Lucas");

programmingLanguages.removeAll(scriptingLanguages);
System.out.println("After removeAll(scriptingLanguages): " + programmingLanguages);
System.out.println(
"Include both Scripting and Programming " + programmingLanguages + scriptingLanguages);

// Remove all the elements that satisfy the given predicate
programmingLanguages.removeIf(
Expand Down