- 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
105 Views
Two byte 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 byte 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 byte[] { 1, 7, 5 }, new byte[] { 1, 7, 5 }); System.out.println("The two byte arrays are ... Read More
225 Views
A multi-dimensional array can be easily printed by using the method java.util.Arrays.deepToString() in Java. This method converts the multi-dimensional array to string and prints the array contents enclosed in square brackets.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String args[]) { int arr [][]= { {5, 8, 6, 3}, {1, 9, 7}, {4, 8, 2}, {6} }; System.out.println("The multi-dimensional array content is:"); System.out.println(Arrays.deepToString(arr)); } }OutputThe multi-dimensional array content is: [[5, 8, 6, 3], [1, 9, 7], [4, 8, ... Read More
304 Views
An array can be sorted in case-sensitive order using the java.util.Arrays.sort() method. Only a single argument required in this case for this method i.e. the array to be sorted. A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String args[]) { String[] arr = new String[] { "apple", "mango", "Banana", "Melon", "orange" }; System.out.print("The unsorted array is: "); System.out.println(Arrays.toString(arr)); Arrays.sort(arr); System.out.print("The sorted array in case-sensitive order is: "); System.out.println(Arrays.toString(arr)); } ... Read More
244 Views
A byte array can be sorted using the java.util.Arrays.sort() method with a single argument required i.e. the array to be sorted. A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] args) { byte[] arr = new byte[] { 4, 1, 9, 7, 5}; System.out.print("The original byte array is: "); for (byte i: arr) { System.out.print(i + " "); } Arrays.sort(arr); System.out.print("The sorted byte array is: "); ... Read More
7K+ Views
The list of all declared fields can be obtained using the java.lang.Class.getDeclaredFields() method as it returns an array of field objects. These field objects include the objects with the public, private, protected and default access but not the inherited fields.Also, the getDeclaredFields() method returns a zero length array if the class or interface has no declared fields or if a primitive type, array class or void is represented in the Class object.A program that demonstrates this is given as follows −Example Live Demoimport java.lang.reflect.*; public class Demo { public static void main(String[] argv) throws Exception { Class ... Read More
3K+ Views
An array of field objects is returned by the method java.lang.Class.getDeclaredFields(). These field objects include the objects with the public, private, protected and default access but not the inherited fields.Also, the getDeclaredFields() method returns a zero length array if the class or interface has no declared fields or if a primitive type, array class or void is represented in the Class object.A program that demonstrates this is given as follows −Example Live Demopackage Test; import java.lang.reflect.*; public class Demo { int i; char c; public Demo(int i, char c) { this.i = i; ... Read More
925 Views
The method java.lang.Class.getDeclaredConstructor() can be used to obtain the constructor object for the private constructor of the class. The parameter for this method is a Class object array that contains the formal parameter types of the constructor.A program that demonstrates this is given as follows −Example Live Demopackage Test; import java.lang.reflect.*; public class Demo { String str; Double d; public Demo(String str, Double d) { this.str = str; this.d = d; } public static void main(String[] args) { try { Demo obj = ... Read More
2K+ Views
The class object associated with the class with the given string name can be returned with the method java.lang.Class.forName(String name, boolean initialize, ClassLoader loader), using the class loader that is used to load the class.The parameters in the forName() method are name, initialize and loader. If the value of the parameter loader is null, then the class is loaded using the bootstrap class loader. Also, if the initialize parameter is true, then only the class is initialized if it has not been initialized earlier.A program that loads the class using the forName() method is given as follows −Example Live Demoimport java.lang.*; ... Read More
89 Views
The getInterfaces() method is used to prove that the interface for a primitive type is an empty array. A program that demonstrates this is given as follows −Example Live Demopackage Test; import java.util.*; public class Demo { public static void main(String[] args) { Class c = int.class; Class[] interfaces = c.getInterfaces(); System.out.println("The Interface is: " + Arrays.asList(interfaces)); } }OutputThe Interface is: []Now let us understand the above program.The int.class is a reference to the Class object for the primitive type int. The interface for this is determined using the getInterfaces() ... Read More
3K+ Views
Two char 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 char 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 char[] { 'a', 'b', 'c' }, new char[] { 'a', 'b', 'c' }); System.out.println("The two char arrays are equal? ... Read More