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

Sai Subramanyam
Published on 03-Jan-2018 12:16:29
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 ... Read More

How to sort a String array in Java?

Lakshmi Srinivas
Published on 03-Jan-2018 12:11:07
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 ... Read More

How to sort Java array elements in ascending order?

Monica Mona
Published on 03-Jan-2018 12:06:01
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 ... Read More

How to sort a random number array in java?

karthikeya Boyini
Published on 03-Jan-2018 12:00:07
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 ... Read More

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

Sharon Christine
Published on 03-Jan-2018 11:55:44
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[]) { ... Read More

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

Swarali Sree
Published on 09-Jan-2018 06:56:17
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 ... Read More

How to convert string to array of integers in java?

Samual Sam
Published on 03-Jan-2018 10:48:05
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 ... Read More

How to convert an Array to a Set in Java?

Sai Subramanyam
Published on 03-Jan-2018 10:44:49
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 ... Read More

How to convert an Array to a Set in Java?

Rahul Sharma
Published on 06-Feb-2018 06:53:29
Following program is converting an Integer[] to Set<Integer>:ExampleLive Demoimport java.util.Arrays; import java.util.HashSet; import java.util.Set; public class Tester {    public static void main(String[] args) {       Integer[] numbers = {1, 2, 3, 4, 5};       Set<Integer> set = new HashSet<Integer>(Arrays.asList(numbers));       System.out.println(set);   ... Read More

How I can reverse a Java Array?

Lakshmi Srinivas
Published on 03-Jan-2018 10:42:26
To reverse an array, swap the first element with the last element and the second element with second last element and so on if the array is of odd length leave the middle element as it is.In short swap the 1st element with the 1st element from last, second element ... Read More
Advertisements