![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9326 Articles for Object Oriented Programming
![Nikitha N](https://www.tutorialspoint.com/assets/profiles/13558/profile/60_76068-1512713229.jpg)
164 Views
The synchronizedList(List list) method of the Collections class accepts a List object and returns a synchronized list backed by the specified list.Example:import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; public class ArrayListSample { public static void main(String[] args){ ArrayList list = new ArrayList(); list.add("JavaFx"); list.add("Java"); list.add("WebGL"); list.add("OpenCV"); Set set = new LinkedHashSet(list); Collections.synchronizedList(list); System.out.println(list); } }Output:[JavaFx, Java, WebGL, OpenCV]
![Srinivas Gorla](https://www.tutorialspoint.com/assets/profiles/13556/profile/60_78057-1512712331.jpg)
308 Views
The Collections class provides a method named reverse() this method accepts a list and reverses the order of elements in it.Example:import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; public class Sample { public static void main(String[] args){ ArrayList list = new ArrayList(); list.add("JavaFx"); list.add("Java"); list.add("WebGL"); list.add("OpenCV"); Set set = new LinkedHashSet(list); System.out.println(set); Collections.reverse(list); System.out.println(list); } }Output:[JavaFx, Java, WebGL, OpenCV] [OpenCV, WebGL, Java, JavaFx]
![Abhinaya](https://www.tutorialspoint.com/assets/profiles/13548/profile/60_54851-1512705920.jpg)
60 Views
The removeLast() method of the java.util.LinkedList class removes and returns the last element of this list.Example:import java.util.*; public class LinkedListDemo { public static void main(String[] args) { LinkedList list = new LinkedList(); list.add("Hello"); list.add(2); list.add("Chocolate"); list.add("10"); System.out.println("LinkedList:" + list); System.out.println("Last element:" + list.removeLast()); System.out.println("LinkedList:" + list); } }Output:LinkedList:[Hello, 2, Chocolate, 10] Last element:10 LinkedList:[Hello, 2, Chocolate]
![Govinda Sai](https://www.tutorialspoint.com/assets/profiles/13542/profile/60_86497-1512650655.jpg)
90 Views
The removeFirst() method of the java.util.LinkedList class removes and returns the first element from this list.Example:import java.util.*; public class LinkedListDemo { public static void main(String[] args) { LinkedList list = new LinkedList(); list.add("Hello"); list.add(2); list.add("Chocolate"); list.add("10"); System.out.println("LinkedList:" + list); System.out.println("First element:" + list.removeFirst()); System.out.println("LinkedList:" + list); } }Output:LinkedList:[Hello, 2, Chocolate, 10] First element:Hello LinkedList:[2, Chocolate, 10]
![Ramu Prasad](https://www.tutorialspoint.com/assets/profiles/13539/profile/60_87996-1512650215.jpg)
78 Views
The getLast() method of the class java.util.LinkedList returns the last element in this list.Example:import java.util.*; public class LinkedListDemo { public static void main(String[] args) { LinkedList list = new LinkedList(); list.add("Hello"); list.add(2); list.add("Chocolate"); list.add("10"); System.out.println("LinkedList:" + list); System.out.println("Last Element :" + list.getLast()); } }Output:LinkedList:[Hello, 2, Chocolate, 10] Last Element :10
![Ankitha Reddy](https://www.tutorialspoint.com/assets/profiles/13550/profile/60_73963-1512711511.jpg)
101 Views
The getFirst() method of the class java.util.LinkedList returns the first element of the current list. Example Live Demo import java.util.*; public class LinkedListDemo { public static void main(String[] args) { LinkedList list = new LinkedList(); list.add("Hello"); list.add(2); list.add("Chocolate"); list.add("10"); System.out.println("LinkedList:" + list); System.out.println("First Element :" + list.getFirst()); } } Output LinkedList:[Hello, 2, Chocolate, 10] First Element :Hello
![Sravani S](https://www.tutorialspoint.com/assets/profiles/13538/profile/60_67753-1512711355.jpg)
125 Views
The addLast(E e) method of the java.util.LinkedList class inserts the specified element at the end of this list.Example:import java.util.*; public class LinkedListDemo { public static void main(String[] args) { LinkedList list = new LinkedList(); list.add("Hello"); list.add(2); list.add("Chocolate"); list.add("10"); System.out.println("LinkedList:" + list); list.addLast("Element"); System.out.println("LinkedList:" + list); } }Output:LinkedList:[Hello, 2, Chocolate, 10] LinkedList:[Hello, 2, Chocolate, 10, Element]
![V Jyothi](https://www.tutorialspoint.com/assets/profiles/13530/profile/60_77592-1512648869.jpg)
132 Views
The addFirst(E e) method of the class java.util.LinkedList inserts the specified element at the beginning of this list.Example:public class LinkedListDemo { public static void main(String[] args) { LinkedList list = new LinkedList(); list.add("Hello"); list.add(2); list.add("Chocolate"); list.add("10"); System.out.println("LinkedList:" + list); list.addFirst("Element"); System.out.println("LinkedList:" + list); } }Output:LinkedList:[Hello, 2, Chocolate, 10] LinkedList:[Element, Hello, 2, Chocolate, 10]
![Priya Pallavi](https://www.tutorialspoint.com/assets/profiles/13562/profile/60_91320-1512544134.jpg)
238 Views
The add(int index, E element) method of the java.util.ArrayList class inserts the specified element E at the specified position in this list. It shifts the element currently at that position (if any) and any subsequent elements to the right (will add one to their indices).Exampleimport java.util.ArrayList; public class ArrayListDemo { public static void main(String[] args) { ArrayList arrlist = new ArrayList(5); arrlist.add(15); arrlist.add(22); arrlist.add(30); arrlist.add(40); arrlist.add(2,25); for (Integer number : arrlist) { System.out.println("Number = " + number); } } }OutputNumber = 15 Number = 22 Number = 25 Number = 30 Number = 40
![Nikitha N](https://www.tutorialspoint.com/assets/profiles/13558/profile/60_76068-1512713229.jpg)
280 Views
The add(E e) method of the java.util.ArrayList class appends the specified element E to the end of the list.Example:import java.util.ArrayList; public class ArrayListDemo { public static void main(String[] args) { ArrayList arrlist = new ArrayList(5); arrlist.add(15); arrlist.add(20); arrlist.add(25); for (Integer number : arrlist) { System.out.println("Number = " + number); } } }Output:Number = 15 Number = 20 Number = 25