Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linked List in Java, How to cast String array into List?

Can you tell me what does this method return type is:

List<passenger> recommend(Car a, Driver b)  { ... }

I just want to know about List keyword. Is this standard linked list or soemthing else.
If i have objects of passenger type. How can I add them in a List?

like image 509
Johnydep Avatar asked Apr 19 '26 04:04

Johnydep


2 Answers

List in java is an interface. It means that it is not a concrete implementation, but the interface to it.

The concrete implementation the method can return can be LinkedList, ArrayList or any other class which implements the List interface. Read more in javadoc.

Basically, you add the elements to the list using methods add or addAll:

list.add(object);
list.addAll(anotherList);
like image 152
Vladimir Ivanov Avatar answered Apr 21 '26 18:04

Vladimir Ivanov


List is an interface. it can be an ArrayList or what ever implements the List interface

List<passenger> list = new ArrayList<passenger>(); 

Basically, it contains a list of passengers.

like image 45
RMT Avatar answered Apr 21 '26 16:04

RMT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!