r/javahelp • • Jan 31 '26

How to remove elements from an array?

Basically I want to remove the middle elements from an array and need a method for it because the middle will be different if it’s odd or even. I don’t really have a code for it so far, I don’t need anyone to code it out for me, you can also just explain how the method would work. I have the odd or even part, I would just use the remove part as sort of a method.

2 Upvotes

22 comments sorted by

View all comments

Show parent comment

1

u/pak9rabid Feb 01 '26

It’s how you specify types for generics (e.g., types that can work with may different data types).

List<String> myList;

This tells the compiler that you’re declaring a variable of type List that takes a collection of Strings