- 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
144 Views
Two float 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 float 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 float[] { 1.5F, 8.3F, 7.6F }, new float[] { 1.5F, 8.3F, 7.6F }); System.out.println("The two float arrays are equal? ... Read More
201 Views
The runtime class of an object can be obtained using the java.lang.Object.getClass(). Also, the getName() method is used to get the name of the class.A program that demonstrates getting the class of an object using the getClass() method is given as follows −Example Live Demopublic class Demo { public static void main (String [] args) { Integer integer = new Integer(10); Class c = integer.getClass(); System.out.println ("The class is: " + c.getName()); c = new Demo().getClass(); System.out.println ("The class is: " + c.getName()); } ... Read More
303 Views
Binary search can be implemented on an array by using the method java.util.Arrays.binarySearch(). This method returns the index of the required element if it is available in the array, otherwise it returns (- (insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array.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[] = { 3, 9, 1, 6, 4}; Arrays.sort(arr); System.out.print("The sorted array is: "); ... Read More
407 Views
An array has a fixed number of values and its size is defined when it is created. Therefore, the size of the array cannot be changed later. To solve this problem, an ArrayList should be used as it implements a resizable array using the List interface.A program that demonstrates ArrayList in Java is given as follows −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]) { ArrayList aList = new ArrayList(); aList.add("Apple"); aList.add("Melon"); aList.add("Orange"); aList.add("Mango"); aList.add("Grapes"); ... Read More
152 Views
An element can be searched in a sorted object array in Java by using the methodjava.util.Arrays.binarySearch(). This method returns the index of the required element if it is available in the array, otherwise it returns (-(insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array. A program that searches the required element in a sorted object array is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] args) { String str[] = { "P", "M", "A", "T", "D"}; ... Read More
402 Views
An array of objects 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[]) throws Exception { String str[] = new String[]{"apple", "orange", "mango", "guava", "melon"}; int n = str.length; System.out.println("The original array of strings is: "); for (int i = 0; i < n; i++) { System.out.println(str[i]); } ... Read More
2K+ Views
One of the methods the Timer class is void scheduleAtFixedRate(TimerTask task, Date firstTime, long period). This method schedules the specified task for repeated fixed-rate execution, beginning at the specified time.In fixed-rate execution, each execution is scheduled with respect to the scheduled run time of the initial execution. Fixed-rate execution is apt for repetitive activities that are respond to absolute time. Likewise, fixed-rate execution is appropriate for scheduling multiple repeating timer tasks that must remain in sync.Declaration − The java.util.Time.scheduleAtFixedRate(TimerTask task, Date firstTime, long period) method is declared as follows −public void scheduleAtFixedRate(TimerTask task, Date firstTime, long period)Here, task is the ... Read More
4K+ Views
The java.util.Arrays.sort() method can be used to sort a subset of the array elements in Java. This method has three arguments i.e. the array to be sorted, the index of the first element of the subset (included in the sorted elements) and the index of the last element of the subset (excluded from the sorted elements). Also, the Arrays.sort() method does not return any value.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[] = { 1, 9, 7, 3, 2, 8, ... Read More
118 Views
Two long 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 long 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 long[] { 450L, 150L, 375L }, new long[] { 450L, 150L, 375L }); System.out.println("The two long arrays are equal? ... Read More
529 Views
An array can be converted into a fixed size list using the java.util.Arrays.asList() method. This method is basically a bridge between array based AP!’s and collection based API’s.A program that demonstrates the conversion of an array into a generic list is given as follows −Example Live Demoimport java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo { public static void main(String[] args) { String str[] = new String[]{"apple", "orange", "mango", "guava", "melon"}; List list = Arrays.asList(str); System.out.println("The list is: " + list); } }The output of the above program is as ... Read More