- 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 4338 Articles for Java 8
![radhakrishna](https://www.tutorialspoint.com/assets/profiles/13544/profile/60_40618-1512640354.jpg)
4K+ Views
The class named Object is the super class of every class in Java. Let’s test it with an example. The java.lang.Class.getSuperclass() returns the Class representing the superclass of the entity (class, interface, primitive type or void) represented by this Class. So, Create a sample concrete class and lets try to get the name of its super class using this method. Example Live Demo public class Test { public static void main(String args[]){ Test obj = new Test(); Class cls = obj.getClass().getSuperclass(); ... Read More
![Govinda Sai](https://www.tutorialspoint.com/assets/profiles/13542/profile/60_86497-1512650655.jpg)
13K+ Views
You can remove an element from the JSONArray object using the remove() method. This method accepts an integer and removes the element in that particular index.Exampleimport org.json.JSONArray; public class RemoveFromJsonArray { public static void main(String args[]) throws Exception { String [] myArray = {"JavaFX", "HBase", "JOGL", "WebGL"}; JSONArray jsArray = new JSONArray(); for (int i=0; i < myArray.length; i++) { jsArray.put(myArray[i]); } System.out.println(jsArray); jsArray.remove(3); System.out.println("After deleting ::"+jsArray); } }Output["JavaFX","HBase","JOGL","WebGL"] After deleting ::["JavaFX","HBase","JOGL"]
![Sai Subramanyam](https://www.tutorialspoint.com/assets/profiles/13512/profile/60_68191-1512710774.jpg)
2K+ Views
The final modifier for finalizing the implementations of classes, methods, and variables. The main purpose of using a class being declared as final is to prevent the class from being subclassed. If a class is marked as final then no class can inherit any feature from the final class. You cannot extend a final class. If you try it gives you a compile time error. Example final class Super { private int data = 30; } public class Sub extends Super{ } Output C:\Sample>javac Sub.java Sub.java:7: error: cannot inherit from final Super public class Sub extends Super{ ^ 1 error
![Ramu Prasad](https://www.tutorialspoint.com/assets/profiles/13539/profile/60_87996-1512650215.jpg)
3K+ Views
The get method of the JSONArray class returns the element at a particular index. Using this method, you can get the elements of the JSONArray object and populate the array with them.Exampleimport java.util.Arrays; import org.json.JSONArray; public class JsonToArray { public static void main(String args[]) throws Exception { String [] myArray = {"JavaFX", "HBase", "JOGL", "WebGL"}; JSONArray jsArray = new JSONArray(); for (int i = 0; i < myArray.length; i++) { jsArray.put(myArray[i]); } System.out.println(jsArray); String[] array = new String[myArray.length]; ... Read More
![Sravani S](https://www.tutorialspoint.com/assets/profiles/13538/profile/60_67753-1512711355.jpg)
7K+ Views
Google provides a library named org.json.JSONArray and, following is the maven dependency to add library to your project. com.googlecode.json-simple json-simple 1.1 The JSONArray class of the org.json package provides put() method. Using this method, you can populate the JSONArray object with the contents of the elements.Exampleimport org.json.JSONArray; public class ArrayToJson { public static void main(String args[]) { String [] myArray = {"JavaFX", "HBase", "JOGL", "WebGL"}; JSONArray jsArray = new JSONArray(); ... Read More
![V Jyothi](https://www.tutorialspoint.com/assets/profiles/13530/profile/60_77592-1512648869.jpg)
129 Views
The Arrays class of java package provides you a method named binarySearch() using this method you can perform a binary search on an array in Java.ExampleLive Demoimport java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { int intArr[] = {30,20,5,12,55}; Arrays.sort(intArr); System.out.println("The sorted int array is:"); for (int number : intArr) { System.out.println("Number = " + number); } int searchVal = 12; int retVal = Arrays.binarySearch(intArr,searchVal); System.out.println("The index of element 12 is : " + retVal); } }OutputThe sorted int array is: Number = 5 Number = 12 Number = 20 Number = 30 Number = 55 The index of element 12 is: 1
![Priya Pallavi](https://www.tutorialspoint.com/assets/profiles/13562/profile/60_91320-1512544134.jpg)
550 Views
Following is the algorithm for heapsort (maxheap).Step 1 − Create a new node at the end of the heap.Step 2 − Assign new value to the node.Step 3 − Compare the value of this child node with its parent.Step 4 − If the value of parent is less than a child, then swap them.Step 5 − Repeat step 3 & 4 until Heap property holds.Exampleimport java.util.Arrays; import java.util.Scanner; public class Heapsort { public static void heapSort(int[] myArray, int length) { int temp; int size = length-1; for (int i ... Read More
![Nikitha N](https://www.tutorialspoint.com/assets/profiles/13558/profile/60_76068-1512713229.jpg)
817 Views
To check to find whether a given array contains three consecutive dates:Convert the given array into a list of type LocalDate.Using the methods of the LocalDate class compare ith, i+1th and i+1th, i+2th elements of the list if equal the list contain 3 consecutive elements.ExampleLive Demoimport java.time.LocalDate; import java.time.Month; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; public class ConsicutiveDate { public static void main(String args[]) { String[] dates = {"5/12/2017", "6/12/2017", "7/12/2017"}; List localDateList = new ArrayList(); for (int i = 0; i
![Srinivas Gorla](https://www.tutorialspoint.com/assets/profiles/13556/profile/60_78057-1512712331.jpg)
615 Views
You can convert an array list of strings to an array list of integers as:ExampleLive Demoimport java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class LamdaExpressions { public static void main(String args[]) { ArrayList list = new ArrayList(); list.add("123"); list.add("223"); list.add("323"); list.add("334"); List listInteger = list.stream().map(s -> Integer.parseInt(s)).collect(Collectors.toList()); System.out.println(listInteger); } }Output[123, 223, 323, 334]
![Abhinanda Shri](https://www.tutorialspoint.com/assets/profiles/13552/profile/60_73264-1512711555.jpg)
2K+ Views
ExampleLive Demoimport java.util.Arrays; public class ArrayWithinAnArray{ public static void main(String args[]) { int[] myArray1 = {23, 56, 78, 91}; int[] myArray2 = {123, 156, 178, 191}; int[] myArray3 = {223, 256, 278, 291}; int[] myArray4 = {323, 356, 378, 391}; int [][] arrayOfArrays = {myArray1, myArray2, myArray3, myArray4}; System.out.println(Arrays.deepToString(arrayOfArrays)); } }Output[[23, 56, 78, 91], [123, 156, 178, 191], [223, 256, 278, 291], [323, 356, 378, 391]]