From the course: Java Algorithms
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Using the built-in linked list data structure in Java - Java Tutorial
From the course: Java Algorithms
Using the built-in linked list data structure in Java
- [Instructor] With an understanding of the LinkedList data structure, we can begin to work with LinkedLists in Java. In fact, we can use the built-in LinkedList type defined in the util package. We'll import java.util and the LinkedList class. To create a LinkedList, we'll write LinkedList and this will contain strings, so we'll put String in the arrow brackets. The LinkedList type is generic and it can hold many different types of data, including custom object data. All we have to do is specify it upon the list creation. We could specify integer, double or custom type but for this example, we're using strings. Let's add some data to the LinkedList. We can add data at the front or the back of the link using addFirst or addLast. We also have the option to add data before or after specific nodes in the list. Let's use add and add a few strings to the list. These will be appended to the back of the list. Now that we have some data, we can look at some of the other built-in operations…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.