- Trending Categories
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 4336 Articles for Java 8
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
610 Views
Elements can be filled in a char array using the java.util.Arrays.fill() method. This method assigns the required char value to the char array in Java. The two parameters required are the array name and the value that is to be stored in the array elements.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { char[] charArray = new char[5]; char charValue = 'A'; Arrays.fill(charArray, charValue); System.out.println("The char array content is: " + Arrays.toString(charArray)); ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
132 Views
Two double arrays can be compared in Java using the java.util.Arrays.equals() method. This method returns true if the arrays are equal and false otherwise. The two arrays are equal if they contain the same number of elements in the same order.A program that compares two double arrays using the Arrays.equals() method is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { boolean flag = Arrays.equals(new double[] { 7.5D, 9.2D, 1.8D }, new double[] { 7.5D, 9.2D, 1.8D }); System.out.println("The two double arrays are equal? ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
8K+ Views
In order to swap elements of ArrayList with Java collections, we need to use the Collections.swap() method. It swaps the elements at the specified positions in the list.Declaration −The java.util.Collections.swap() method is declared as follows −public static void swap(List list, int i, int j)where i is the index of the first element to be swapped, j is the index of the other element to be swapped and list is the list where the swapping takes place.Let us see a program to swap elements of ArrayList with Java collections −Example Live Demoimport java.util.*; public class Example { public static void ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
3K+ Views
In order to shuffle elements of ArrayList with Java Collections, we use the Collections.shuffle() method. The java.util.Collections.shuffle() method randomly permutes the list using a default source of randomness.Declaration −The java.util.Collections.shuffle() method is declared as follows −public static void shuffle(List list)Let us see a program to shuffle elements of ArrayList with Java Collections −Example Live Demoimport java.util.*; public class Example { public static void main (String[] args) { ArrayList list = new ArrayList(); list.add(1); list.add(2); list.add(7); list.add(8); list.add(3); list.add(9); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
2K+ Views
In order to reverse order of all elements of ArrayList with Java Collections, we use the Collections.reverse() method.Declaration −The java.util.Collections.reverse method is declared as follows −public static void reverse(List list)Let us see a program to reverse order of all elements of ArrayList with Java Collections −Example Live Demoimport java.util.*; public class Example { public static void main (String[] args) { ArrayList list = new ArrayList(); list.add(1); list.add(2); list.add(7); list.add(8); list.add(3); list.add(9); System.out.println("Original list : " + ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
1K+ Views
In order to replace all occurrences of specified element of ArrayList with Java Collections, we use the Collections.replaceAll() method. This method returns true if list contains one or more elements e such that (oldVal==null ? e==null : oldVal.equals(e)).Declaration −The java.util.Collections.replaceAll() is declared as follows −public static boolean replaceAll(List list, T oldVal, T newVal)where oldVal is the element value in the list to be replaced, newVal is the element value with which it is replaced and list is the list in which replacement takes place.Let us see a program to replace all occurrences of specified element of ArrayList with Java ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
2K+ Views
In order to replace all elements of ArrayList with Java Collections, we use the Collections.fill() method. The static void fill(List list, Object element) method replaces all elements in the list with the specified element in the argument.Declaration −The java.util.Collections.fill() method is declared as follows −public static void fill(List
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
In order to perform Binary Search on ArrayList with Java Collections, we use the Collections.binarySearch() method.Declaration −The java.util.Collections.binarySearch() method is declared as follows −public static int binarySearch(List list, T key)The above method returns the position of the key in the list sorted in ascending order. If we use a Comparator c to sort the list, the binarySearch() method will be declared as follows −public static int binarySearch(List list, T key, Comparator c)If key is not present, the it returns ((insertion point) + 1) *(-1).Let us see a program to perform binarySearch() on ArrayList −Example Live Demoimport java.util.*; public class Example { ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
243 Views
Two short arrays can be compared in Java using the java.util.Arrays.equals() method. This method returns true if the arrays are equal and false otherwise. The two arrays are equal if they contain the same number of elements in the same order.A program that compares two short arrays using the Arrays.equals() method is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { boolean flag = Arrays.equals(new short[] { 2, 8, 5 }, new short[] { 2, 8, 5 }); System.out.println("The two short arrays are equal? ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
452 Views
In order to get enumeration over ArrayList with Java Collections, we use the java.util.Collections.enumeration() method.Declaration −The java.util.Collections.enumeration() method is declared is as follows −public static Enumeration enumeration(Collection c)where c is the collection object for which an enumeration is returnedLet us see a program to get enumeration over ArrayList −Example Live Demoimport java.util.*; public class Example { public static void main (String[] args) { ArrayList list = new ArrayList(); list.add(14); list.add(2); list.add(73); Enumeration en = Collections.enumeration(list); // getting enumeration over ArrayList list ... Read More