
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Difference between Streams and Collections in Java 8
Java Collections framework is used for storing and manipulating group of data. It is an in-memory data structure and every element in the collection should be computed before it can be added in the collections.
Stream API is only used for processing group of data. It does not modify the actual collection, they only provide the result as per the pipelined methods.
Sr. No. | Key | Collections | Streams |
---|---|---|---|
1 | Basic | It is used for storing and manipulating group of data | Stream API is only used for processing group of data |
2 | Package | All the classes and interfaces of this API is in the Java.util package | All the classes and interfaces of this API is in the java.util.stream package |
3 | Eager/Lazy | All the elements in the collections are computed in the beginning. | In streams, intermediate operations are lazy. |
4. | Data Modification | In collections, we can remove or add elements. | We can’t modify streams. |
5 | External /Internal iterator | Collections perform iteration over the collection. | Stream perform iteration internally. |
Example of Collections
public class CollectiosExample { public static void main(String[] args) { List<String> laptopList = new ArrayList<>(); laptopList.add("HCL"); laptopList.add("Apple"); laptopList.add("Dell"); Comparator<String> com = (String o1, String o2)->o1.compareTo(o2); Collections.sort(laptopList,com); for (String name : laptopList) { System.out.println(name); } } }
Example of Streams
public class StreamsExample { public static void main(String[] args) { List<String> laptopList = new ArrayList<>(); laptopList.add("HCL"); laptopList.add("Apple"); laptopList.add("Dell"); laptopList.stream().sorted().forEach(System.out::println); } }
- Related Articles
- Difference between Traditional Collections and Concurrent Collections in java
- Difference between collection and collections in java
- Difference between next() and hasNext() in java collections?
- Java 8 Streams and its operations
- Streams on Arrays in Java 8
- What is the difference between System.out, System.in and System.err streams in Java?
- Differences between Collection and Collections in Java?
- Difference between Function and Predicate in Java 8
- What is the difference between cerr and clog streams in c++?
- What is the difference between cerr and cout streams in c++?
- What is the difference between cin and cout streams in c++?
- Difference between intermediate and terminal operations in Java 8
- Difference between default and static interface method in Java 8.
- Streams in Java
- What is the necessity of byte streams and character streams in Java?

Advertisements