Found 4338 Articles for Java 8

What is the difference between Java references and pointers in other languages?

Ali
Ali
Updated on 30-Jul-2019 22:30:20

240 Views

Reference datatypes in java are those which contains reference/address of dynamically created objects. These are not predefined like primitive data types. Following are the reference types in Java. class types − This reference type points to an object of a class. array types − This reference type points to an array. interface types − This reference type points to an object of a class which implements an interface. Once we create a variable of these types (i.e. when we create an array or object, class or interface). These variables only store the address of these values. Default ... Read More

What are reference data types in Java?

Rahul Sharma
Updated on 30-Jul-2019 22:30:20

8K+ Views

Reference datatypes in java are those which contains reference/address of dynamically created objects. These are not predefined like primitive data types. Following are the reference types in Java. class types − This reference type points to an object of a class. array types − This reference type points to an array. interface types − This reference type points to an object of a class which implements an interface. Once we create a variable of these types (i.e. when we create an array or object, class or interface). These variables only store the address of these values. Default ... Read More

How to sort an array of objects containing null elements in java?

Sai Subramanyam
Updated on 16-Jun-2020 11:50:33

2K+ Views

Whenever we try to sort elements with null values using the sort method it throws an exception.The sort() method of the Arrays class also accepts a Comparator along with the array. Using comparator, you need to specify the order in which the elements need to be sorted.Using this method push all the null elements to last and sort the elements −Example Live Demoimport java.util.Arrays; import java.util.Comparator; public class ArrayWithNullsInOrder { public static void main(String args[]) { String[] myArray = {"JavaFX", null, "OpenCV", null, "Hadoop", null}; Arrays.sort(myArray, Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)); System.out.println(Arrays.toString(myArray)); } }Output[Hadoop, JavaFX, OpenCV, null, null, null]Read More

How to sort a String array in Java?

Lakshmi Srinivas
Updated on 19-Feb-2020 10:45:55

13K+ Views

To sort a String array in Java, you need to compare each element of the array to all the remaining elements, if the result is greater than 0, swap them.One solution to do so you need to use two loops (nested) where the inner loop starts with i+1 (where i is the variable of outer loop) to avoid repetitions in comparison.ExampleLive Demoimport java.util.Arrays; public class StringArrayInOrder {    public static void main(String args[]) {       String[] myArray = {"JavaFX", "HBase", "OpenCV", "Java", "Hadoop", "Neo4j"};       int size = myArray.length;       for(int i = 0; i

How to sort Java array elements in ascending order?

Monica Mona
Updated on 19-Feb-2020 10:44:56

630 Views

To sort an array in Java, you need to compare each element of the array to all the remaining elements and verify whether it is greater if so swap them.One solution to do so you need to use two loops (nested) where the inner loop starts with i+1 (where i is the variable of outer loop) to avoid repetitions in comparison.Exampleimport java.util.Arrays; import java.util.Scanner; public class ArrayInOrder {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter the size of the array that is to be created::");     ... Read More

How to sort a random number array in java?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:20

2K+ Views

To sort an array in Java, you need to compare each element of the array to all the remaining elements and verify whether it is greater if so swap them.One solution to do so you need to use two loops (nested) where the inner loop starts with i+1 (where i is the variable of outer loop) to avoid repetitions in comparison.Example Live Demoimport java.util.Arrays; import java.util.Scanner; public class ArrayInOrder {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter the size of the array that is to be created::");   ... Read More

How to convert a Double array to a String array in java?

Sharon Christine
Updated on 19-Feb-2020 10:44:05

3K+ Views

You can convert a double array to a string using the toString() method. To convert a double array to a string array, convert each element of it to string and populate the String array with them.ExampleLive Demoimport java.util.Arrays; public class DoubleArrayToString {    public static void main(String args[]) {       Double[] arr = {12.4, 35.2, 25.6, 98.7, 56.4};       int size = arr.length;       String[] str = new String[size];           for(int i=0; i

How to convert/store a string of numbers in to an array in java?

Swarali Sree
Updated on 30-Jul-2019 22:30:21

2K+ Views

You can convert a String to an integer using the parseInt() method of the Integer class. To convert a string array to an integer array, convert each element of it to integer and populate the integer array with them.Example Live Demoimport java.util.Arrays; public class StringToIntegerArray {    public static void main(String args[]) {       String [] str = {"123", "345", "437", "894"};       int size = str.length;       int [] arr = new int [size];       for(int i=0; i

How to convert string to array of integers in java?

Samual Sam
Updated on 06-Sep-2023 12:59:19

40K+ Views

You can convert a String to integer using the parseInt() method of the Integer class. To convert a string array to an integer array, convert each element of it to integer and populate the integer array with them.Example Live Demoimport java.util.Arrays; public class StringToIntegerArray { public static void main(String args[]) { String [] str = {"123", "345", "437", "894"}; int size = str.length; int [] arr = new int [size]; for(int i=0; i

How to convert an Array to a Set in Java?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:20

2K+ Views

One solution to add an array to set is to use the addAll() method of the Collections class. This method accepts a collection and an element and, it adds the given element to the specified Collection. Example Live Demo import java.util.Collections; import java.util.HashSet; import java.util.Set; public class ArrayToSet { public static void main(String args[]) { Integer[] myArray = {23, 93, 56, 92, 39}; Set set = new HashSet(); Collections.addAll(set, myArray); System.out.println(set); } } Output [23, 39, 56, 92, 93]

Advertisements