In javadoc about ArrayList you can read about the method add(E e) where e is an element. What's the differense between elements and objects? I am interested in how the elements are different from objects in Java, not generics .
-
2An element is an object for all intents and purposes. – Jeroen Vannevel Apr 03 '16 at 18:53
-
1There's not much to it really. It's just a convention that the word `element` is used for items in a `List` or a `Set`. It's not the same as an `Object` because you can put `null` references in a `List` too. – Paul Boddington Apr 03 '16 at 18:53
-
@PaulBoddington Isn't that `E` a generic? – Debosmit Ray Apr 03 '16 at 18:55
-
1@DebosmitRay I think the OP is asking about the word "element" rather than the type parameter `E`. I'm not really sure. – Paul Boddington Apr 03 '16 at 18:56
-
correctly @Paul Boddington! – user1991275 Apr 03 '16 at 19:43
3 Answers
Elements are no different from Objects in Java.
In real life though
It is a part of good practices used when using Java, but they all design Objects. Knowing that in Java, when writing classes using genericity, you may use the names you want like below
public class MyClass<IChooseTheNameIWant> {} // This is totally valid.
public class MyClass<T> {} // This is valid AND respects good practices.
It is better to follow the good practices to ensure durability/readability (for others) of your code. And this is what the Java language architects did when designing ArrayList
.
Generics : How They Work?
Type parameters, also known as type variables, are used as placeholders to indicate that a type will be assigned to the class at runtime. There may be one or more type parameters, and they can be utilized throughout the class, as needed. By convention, type parameters are a single uppercase letter, and the letter that is used indicates the type of parameter being defined. The following list contains the standard type parameters for each use case:
E: Element K: Key N: Number T: Type V: Value S, U, V, and so on: Second, third, and fourth types in a multiparameter situation

- 21,337
- 9
- 51
- 89
-
I don't think the question is about generics. It asks about the word "element" in the Javadoc for the `add` method. I think the OP wants to know why the Javadoc doesn't say "Appends the specified object to the end of this list". – RealSkeptic Apr 03 '16 at 19:05
-
@RealSkeptic Well doesn't my answer give an explaination about that? What do you advice me to add? – Yassin Hajaj Apr 03 '16 at 19:08
In that context Element is a Generic Object
example: you can not do List<int>
instead mus use the class Integer and do List<Integer>

- 47,427
- 17
- 69
- 97
In general, an element is a part of a whole. For example, the number 4 is an element in 1,2,4,8
. The number 16 and the string elephant
are not.
In Java, the elements of a list can be references to objects, or the special null
value that references no object.

- 108,737
- 14
- 143
- 193