very very rougly sorting - java

Suppose we have an array ( int[] m ).
I need sort it... Result must be:
all items in the first half must be less or equal than any items in the second half.
how to do it?...

As Karl already mentioned in his comment, the task is equal to a partinioning step in the quicksort algorithm with the exception that you have to find the sample median first and use it as the pivot element.
Computing a median can be computed with O(n) operations, the partinioning step is linear too (O(n)), so the overall worst-case performance is still better than a full sorting (O(n log(n)).
The algorithm will go like this (standard methods need to be implemented):
public int[] roughSort(int[] input) {
int pivot = findMedian(input);
int[] result = partition(input, pivot);
return result;
}

Arrays.sort(array);
for (int i : array) {
System.out.println(i);
}
Sorting it in ascending order shall be ok for your case.

List<Integer> list = new ArrayList<Integer>();
list.add(2);
list.add(5);
list.add(1);
list.add(15);
list.add(55);
list.add(23);
Collections.sort(list);
int length = list.size();
List<Integer> list1 = list.subList(0, length/2);
List<Integer> list2 = list.subList(length/2, length);
Collections.shuffle(list1);
Collections.shuffle(list2);
List<Integer> newList = new ArrayList<Integer>();
newList.addAll(list1);
newList.addAll(list2);
System.out.println(newList);
Is this what you wanted?

Related

i need a quicksort where the first element of the relevant subarray is the pivot point

So I need to make a quicksort where you use the first element and compare it to all other elements and that first elements new position will become the pivot point. Please help me.
You can do it by creating 3 lists and separate values depending on whether they are higher than pivot, lower than pivot, or equal to pivot. For example:
public static List<Integer> quickSort(List<Integer> n) {
List<Integer> low = new ArrayList<Integer>();
List<Integer> piv = new ArrayList<Integer>();
List<Integer> high = new ArrayList<Integer>();
int pivot = n.get(0);
for (Integer d : n) {
if (d < pivot)
low.add(d);
else if (d > pivot)
high.add(d);
else
piv.add(d);
}
low.addAll(piv);
low.addAll(high);
return low;

Complexity of the following code

I was given the following task:
Given - 2 list. Size of the first list is N1, size of the second list is N2. Each list don't have the same elements.
Write a code that create a new list with elements from first and second lists. This list also shouldn't have the same elements.
Also estimate the complexity of your code.
I write the followin code:
public class Lists {
static ArrayList<Integer> getNewList(ArrayList<Integer> list1,
ArrayList<Integer> list2) {
ArrayList<Integer> tmp = new ArrayList<>();
for (Integer i : list1) {
tmp.add(i);
}
for (Integer i : list2) {
if (!list1.contains(i))
tmp.add(i);
}
return tmp;
}
public static void main(String[] args) {
Integer[] arr1 = {1, 2, 3, 14, 15, 16};
Integer[] arr2 = {3, 6, 7, 8, 14};
ArrayList<Integer> list1 = new ArrayList<>(Arrays.asList(arr1));
ArrayList<Integer> list2 = new ArrayList<>(Arrays.asList(arr2));
for (Integer i : getNewList(list1, list2)) {
System.out.print(i + " ");
}
}
}
and say that time of execution of getNewList method would be proportional to N1*N2. In reply I receive the following without any explanation - "You are wrong, the complexity of this code is not N1*N2".
So can someone tell what is the right answer? And explain how complexity is determine?
The complexity of your code is O(N1*N2), but you can do much better by using a HashSet to determine which numbers appear in both Lists :
static ArrayList<Integer> getNewList(ArrayList<Integer> list1,
ArrayList<Integer> list2) {
ArrayList<Integer> tmp = new ArrayList<>();
HashSet<Integer> dups = new HashSet<>();
tmp.addAll(list1);
dups.addAll(list1);
for (Integer i : list2) {
if (!dups.contains(i))
tmp.add(i);
}
return tmp;
}
This would give you O(N1+N2) running time, since insertion and lookup take expected O(1) time in HashSet.
Well, the short answer to your question is: complexity is N1 + (N2*N1)/2 + N3 (size of the new list), which should be in O(N1*N2)
Breakdown:
for (Integer i : list1) {
tmp.add(i);
}
-> clearly, this is N1
for (Integer i : list2) {
if (!list1.contains(i))
tmp.add(i);
}
-> list2 iteration => N2
-> for each of this iteration, you call .contain method
which uses sequential search, resulting in N1/2 iterations (on average)
-> So, you get N2*N1/2
In the main you have a loop, iterating from 0 until N3 (which is the length of the new List)
So, overall you get N1 + (N2*N1)/2 + N3, which should be in O(N1*N2)
I'm definitely seeing O(N1 * N2) complexity here too. I'm guessing your professor overlooked the cost of the contains call in the following:
for (Integer i : list2) {
if (!list1.contains(i))
tmp.add(i);
}
contains on ArrayList is O(N) complexity. Since your loop over list2 is also O(N), you end up with O(N1 * N2).
Thanks for #Slanec's explanation, I recheck the implementation of contains(Object obj) in JDK and find it is as below
public boolean contains(Object obj) {
return indexOf(obj) >= 0;
}
public int indexOf(Object obj) {
if (obj == null) {
for (int i = 0; i < size; i++)
if (elementData[i] == null)
return i;
} else {
for (int j = 0; j < size; j++)
if (obj.equals(elementData[j]))
return j;
}
return -1;
}
Obviously, the time complexity of contains(Object obj) is O(n).(I thought it was O(1) at first)
So the time complexity of the code should be O(N1 * N2) but not O(n).

Getting IndexOutOfBoundException

why does following main method gives IndexOutOfBoundException at list.add(1, 2)?
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(1, 2);
int total = list.get(0);
System.out.println(total);
}
You can't add an element at index 1 when it the ArrayList is empty. It starts at 0, or just use add.
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
int total = list.get(0); // <-- You even use 0 here!
System.out.println(total);
}
Per the ArrayList#add(int index, E element) javadoc,
Throws:
IndexOutOfBoundsException - if the index is out of range
(index < 0 || index > size())
When size == 0, the index 1 is out of range.
Here's the problem:
list.add(1, 2);
To fix it, do this:
list.add(0, 2);
Or even simpler, this:
list.add(2);
Remember: in Java, lists an arrays start at index 0, you'll get an error if you try to add an element at index 1 in an empty list.
List maintains the insertion order.
We are trying to add an element at index 1, when the list is empty, that is why it results in java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
Quick Solutions:-
Add elements in the list using add() method of the Collection interface.
List list = new ArrayList();
list.add(1);
list.add(2);
Add elements to the list using add(int index, T t) method of the List interface.
List list = new ArrayList();
list.add(0, 1); // Filling 0th index with value 1.
list.add(1, 2); // Filling 1th index with value 2.

Is there a way to find common elements in multiple lists?

I have a list of integer arrays. I need to find the common elements between those. What I can think of is an extension of what is listed in Common elements in two lists
Example would be
[1,3,5],
[1,6,7,9,3],
[1,3,10,11]
should result in [1,3]
There are no duplicates in the arrays as well.
Is there a straight forward way to do this?
You can transform the lists to sets, and then use Set.retainAll method for intersection between the different sets.
Once you intersect all sets, you are left with the common elements, and you can transform the resulting set back to a list.
You can use Set's intersection method offered by Guava, Here is a little example :
public <T> Set<T> intersection(List<T>... list) {
Set<T> result = Sets.newHashSet(list[0]);
for (List<T> numbers : list) {
result = Sets.intersection(result, Sets.newHashSet(numbers));
}
return result;
}
Hope that could help you
We can use retainAll method of Collections. I initialised my commons arraylist with the first array list and called this for each remaining arraylists.
List<List<Integer>> lists = new ArrayList<List<Integer>>();
lists.add(new ArrayList<Integer>(Arrays.asList(1, 3, 5)));
lists.add(new ArrayList<Integer>(Arrays.asList(1, 6, 7, 9, 3)));
lists.add(new ArrayList<Integer>(Arrays.asList(1, 3, 10, 11)));
List<Integer> commons = new ArrayList<Integer>();
commons.addAll(lists.get(1));
for (ListIterator<List<Integer>> iter = lists.listIterator(1); iter.hasNext(); ) {
commons.retainAll(iter.next());
}
System.out.println(commons);
System.out.println(lists.get(1));
with Java 8
ArrayList retain = list1.stream()
.filter(list2::contains).filter(list3::contains).collect(toList())
If you are looking for a function that returns elements that exist in all lists,
then the straight forward & simple way is building a statistic { < member, occurences > }
The condition here is no duplicates among the same list,
private Set<Integer> getCommonElements(ArrayList<Integer[]> idList)
{
MapList<Integer,Short> stat = new MapList<Integer,Short>();
// Here we count how many times each value occur
for (int i = 0; i < idList.size(); i++)
{
for (int j = 0; j < idList.get(i).size; j++)
{
if (stat.containsKey(idList.get(i)[j]))
{
stat.set(idList.get(i)[j], stat.get(idList.get(i)[j])+1);
}
else
{
stat.add(idList.get(i)[j], 1);
}
}
}
// Here we only keep value that occured in all lists
for (int i = 0; i < stat.size(); i++)
{
if (stat.get(i) < idList.size())
{
stat.remove(i);
i--;
}
}
return stat.keySet();
}
public class ArrayListImpl{
public static void main(String s[]){
ArrayList<Integer> al1=new ArrayList<Integer>();
al1.add(21);al1.add(23);al1.add(25);al1.add(26);
ArrayList<Integer> al2=new ArrayList<Integer>();
al2.add(15);al2.add(16);al2.add(23);al2.add(25);
ArrayList Al3=new ArrayList<Integer>();
al3.addAll(al1);
System.out.println("Al3 Elements :"+al3);
al3.retainAll(al2); //Keeps common elements of (al1 & al2) & removes remaining elements
System.out.println("Common Elements Between Two Array List:"+al3);
}
}
If you are using JAVA 8 streams. Then using stream reduce operation we can achieve the same.
Considering your example: Let's say
a = [1,3,5], b = [1,6,7,9,3] and c = [1,3,10,11]
List<Integer> commonElements = Stream.of(a,b,c)
.reduce((s1,s2) -> {
s1.retainAll(s2);
return s1;
}).orElse(Collections.emptyList());
Keep in mind that after running this operation a will get modified with common values as well. So you will lose the actual value of a.
So elements of a and the result elements of commonElements will be essentially the same after running this operation.
Giving some another alternative code using retainAll capability of Set
public List getCommonItems(List... lists) {
Set<Integer> result = new HashSet<>(lists[0]);
for (List list : lists) {
result.retainAll(new HashSet<>(list));
}
return new ArrayList<>(result);;
}
Usage:
List list1 = [1, 2, 3]
List list2 = [3, 2, 1]
List list3 = [2, 5, 1]
List commonItems = getCommonItems(list1, list2, list3)
System.out.println("Common items: " + result);
Result:
commonItems: [1, 2]
public class commonvalue {
Public static void MyMethod(){
Set<integer> S1 = new set<integer>{1,3,5};
Set<integer> S2 = new set<integer>{1,6,7,9,3};
Set<integer> S3 = new set<integer>{1,3,10,11};
s2.retainall(s1);
s3.retainall(s2);
system.debug(s3);
}
}

Java Array Sort descending?

Is there any EASY way to sort an array in descending order like how they have a sort in ascending order in the Arrays class?
Or do I have to stop being lazy and do this myself :[
You could use this to sort all kind of Objects
sort(T[] a, Comparator<? super T> c)
Arrays.sort(a, Collections.reverseOrder());
Arrays.sort() cannot be used directly to sort primitive arrays in descending order. If you try to call the Arrays.sort() method by passing reverse Comparator defined by Collections.reverseOrder() , it will throw the error
no suitable method found for sort(int[],comparator)
That will work fine with 'Array of Objects' such as Integer array but will not work with a primitive array such as int array.
The only way to sort a primitive array in descending order is, first sort the array in ascending order and then reverse the array in place. This is also true for two-dimensional primitive arrays.
for a list
Collections.sort(list, Collections.reverseOrder());
for an array
Arrays.sort(array, Collections.reverseOrder());
You can use this:
Arrays.sort(data, Collections.reverseOrder());
Collections.reverseOrder() returns a Comparator using the inverse natural order. You can get an inverted version of your own comparator using Collections.reverseOrder(myComparator).
an alternative could be (for numbers!!!)
multiply the Array by -1
sort
multiply once again with -1
Literally spoken:
array = -Arrays.sort(-array)
without explicit comparator:
Collections.sort(list, Collections.reverseOrder());
with explicit comparator:
Collections.sort(list, Collections.reverseOrder(new Comparator()));
It's not directly possible to reverse sort an array of primitives (i.e., int[] arr = {1, 2, 3};) using Arrays.sort() and Collections.reverseOrder() because those methods require reference types (Integer) instead of primitive types (int).
However, we can use Java 8 Stream to first box the array to sort in reverse order:
// an array of ints
int[] arr = {1, 2, 3, 4, 5, 6};
// an array of reverse sorted ints
int[] arrDesc = Arrays.stream(arr).boxed()
.sorted(Collections.reverseOrder())
.mapToInt(Integer::intValue)
.toArray();
System.out.println(Arrays.toString(arrDesc)); // outputs [6, 5, 4, 3, 2, 1]
First you need to sort your array using:
Collections.sort(myArray);
Then you need to reverse the order from ascending to descending using:
Collections.reverse(myArray);
Java 8:
Arrays.sort(list, comparator.reversed());
Update:
reversed() reverses the specified comparator. Usually, comparators order ascending, so this changes the order to descending.
For array which contains elements of primitives if there is org.apache.commons.lang(3) at disposal easy way to reverse array (after sorting it) is to use:
ArrayUtils.reverse(array);
When an array is a type of Integer class then you can use below:
Integer[] arr = {7, 10, 4, 3, 20, 15};
Arrays.sort(arr, Collections.reverseOrder());
When an array is a type of int data type then you can use below:
int[] arr = {7, 10, 4, 3, 20, 15};
int[] reverseArr = IntStream.rangeClosed(1, arr.length).map(i -> arr[arr.length-i]).toArray();
I don't know what your use case was, however in addition to other answers here another (lazy) option is to still sort in ascending order as you indicate but then iterate in reverse order instead.
For discussions above, here is an easy example to sort the primitive arrays in descending order.
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] nums = { 5, 4, 1, 2, 9, 7, 3, 8, 6, 0 };
Arrays.sort(nums);
// reverse the array, just like dumping the array!
// swap(1st, 1st-last) <= 1st: 0, 1st-last: nums.length - 1
// swap(2nd, 2nd-last) <= 2nd: i++, 2nd-last: j--
// swap(3rd, 3rd-last) <= 3rd: i++, 3rd-last: j--
//
for (int i = 0, j = nums.length - 1, tmp; i < j; i++, j--) {
tmp = nums[i];
nums[i] = nums[j];
nums[j] = tmp;
}
// dump the array (for Java 4/5/6/7/8/9)
for (int i = 0; i < nums.length; i++) {
System.out.println("nums[" + i + "] = " + nums[i]);
}
}
}
Output:
nums[0] = 9
nums[1] = 8
nums[2] = 7
nums[3] = 6
nums[4] = 5
nums[5] = 4
nums[6] = 3
nums[7] = 2
nums[8] = 1
nums[9] = 0
Another solution is that if you're making use of the Comparable interface you can switch the output values which you had specified in your compareTo(Object bCompared).
For Example :
public int compareTo(freq arg0)
{
int ret=0;
if(this.magnitude>arg0.magnitude)
ret= 1;
else if (this.magnitude==arg0.magnitude)
ret= 0;
else if (this.magnitude<arg0.magnitude)
ret= -1;
return ret;
}
Where magnitude is an attribute with datatype double in my program. This was sorting my defined class freq in reverse order by it's magnitude. So in order to correct that, you switch the values returned by the < and >. This gives you the following :
public int compareTo(freq arg0)
{
int ret=0;
if(this.magnitude>arg0.magnitude)
ret= -1;
else if (this.magnitude==arg0.magnitude)
ret= 0;
else if (this.magnitude<arg0.magnitude)
ret= 1;
return ret;
}
To make use of this compareTo, we simply call Arrays.sort(mFreq) which will give you the sorted array freq [] mFreq.
The beauty (in my opinion) of this solution is that it can be used to sort user defined classes, and even more than that sort them by a specific attribute. If implementation of a Comparable interface sounds daunting to you, I'd encourage you not to think that way, it actually isn't. This link on how to implement comparable made things much easier for me. Hoping persons can make use of this solution, and that your joy will even be comparable to mine.
For 2D arrays to sort in descending order you can just flip the positions of the parameters
int[][] array= {
{1, 5},
{13, 1},
{12, 100},
{12, 85}
};
Arrays.sort(array, (a, b) -> Integer.compare(a[1], b[1])); // for ascending order
Arrays.sort(array, (b, a) -> Integer.compare(a[1], b[1])); // for descending order
Output for descending
12, 100
12, 85
1, 5
13, 1
You could use stream operations (Collections.stream()) with Comparator.reverseOrder().
For example, say you have this collection:
List<String> items = new ArrayList<>();
items.add("item01");
items.add("item02");
items.add("item03");
items.add("item04");
items.add("item04");
To print the items in their "natural" order you could use the sorted() method (or leave it out and get the same result):
items.stream()
.sorted()
.forEach(item -> System.out.println(item));
Or to print them in descending (reverse) order, you could use the sorted method that takes a Comparator and reverse the order:
items.stream()
.sorted(Comparator.reverseOrder())
.forEach(item -> System.out.println(item));
Note this requires the collection to have implemented Comparable (as do Integer, String, etc.).
There is a lot of mess going on here - people suggest solutions for non-primitive values, try to implement some sorting algos from the ground, give solutions involving additional libraries, showing off some hacky ones etc. The answer to the original question is 50/50. For those who just want to copy/paste:
// our initial int[] array containing primitives
int[] arrOfPrimitives = new int[]{1,2,3,4,5,6};
// we have to convert it into array of Objects, using java's boxing
Integer[] arrOfObjects = new Integer[arrOfPrimitives.length];
for (int i = 0; i < arrOfPrimitives.length; i++)
arrOfObjects[i] = new Integer(arrOfPrimitives[i]);
// now when we have an array of Objects we can use that nice built-in method
Arrays.sort(arrOfObjects, Collections.reverseOrder());
arrOfObjects is {6,5,4,3,2,1} now. If you have an array of something other than ints - use the corresponding object instead of Integer.
Simple method to sort an int array descending:
private static int[] descendingArray(int[] array) {
Arrays.sort(array);
int[] descArray = new int[array.length];
for(int i=0; i<array.length; i++) {
descArray[i] = array[(array.length-1)-i];
}
return descArray;
}
Adding my answer in here for a couple of different scenarios
For an Array
Arrays.sort(a, Comparator.reverseOrder());
FWIW Lists
Lists.reverse(a);
Any and all Collections
Collections.reverse(a);
I know that this is a quite old thread, but here is an updated version for Integers and Java 8:
Arrays.sort(array, (o1, o2) -> o2 - o1);
Note that it is "o1 - o2" for the normal ascending order (or Comparator.comparingInt()).
This also works for any other kinds of Objects. Say:
Arrays.sort(array, (o1, o2) -> o2.getValue() - o1.getValue());
This worked for me:
package doublearraysort;
import java.util.Arrays;
import java.util.Collections;
public class Gpa {
public static void main(String[] args) {
// initializing unsorted double array
Double[] dArr = new Double[] {
new Double(3.2),
new Double(1.2),
new Double(4.7),
new Double(3.3),
new Double(4.6),
};
// print all the elements available in list
for (double number : dArr) {
System.out.println("GPA = " + number);
}
// sorting the array
Arrays.sort(dArr, Collections.reverseOrder());
// print all the elements available in list again
System.out.println("The sorted GPA Scores are:");
for (double number : dArr) {
System.out.println("GPA = " + number);
}
}
}
Output:
GPA = 3.2
GPA = 1.2
GPA = 4.7
GPA = 3.3
GPA = 4.6
The sorted GPA Scores are:
GPA = 4.7
GPA = 4.6
GPA = 3.3
GPA = 3.2
GPA = 1.2
public double[] sortArrayAlgorithm(double[] array) { //sort in descending order
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array.length; j++) {
if (array[i] >= array[j]) {
double x = array[i];
array[i] = array[j];
array[j] = x;
}
}
}
return array;
}
just use this method to sort an array of type double in descending order, you can use it to sort arrays of any other types(like int, float, and etc) just by changing the "return type", the "argument type" and the variable "x" type to the corresponding type. you can also change ">=" to "<=" in the if condition to make the order ascending.
Another way with Comparator
import java.util.Arrays;
import java.util.Comparator;
...
Integer[] aInt = {6,2,3,4,1,5,7,8,9,10};
Arrays.sort(aInt, Comparator.reverseOrder() );
It's good sometimes we practice over an example, here is a full one:
sortdesc.java
import java.util.Arrays;
import java.util.Collections;
class sortdesc{
public static void main(String[] args){
// int Array
Integer[] intArray=new Integer[]{
new Integer(15),
new Integer(9),
new Integer(16),
new Integer(2),
new Integer(30)};
// Sorting int Array in descending order
Arrays.sort(intArray,Collections.reverseOrder());
// Displaying elements of int Array
System.out.println("Int Array Elements in reverse order:");
for(int i=0;i<intArray.length;i++)
System.out.println(intArray[i]);
// String Array
String[] stringArray=new String[]{"FF","PP","AA","OO","DD"};
// Sorting String Array in descending order
Arrays.sort(stringArray,Collections.reverseOrder());
// Displaying elements of String Array
System.out.println("String Array Elements in reverse order:");
for(int i=0;i<stringArray.length;i++)
System.out.println(stringArray[i]);}}
compiling it...
javac sortdec.java
calling it...
java sortdesc
OUTPUT
Int Array Elements in reverse order:
30
16
15
9
2
String Array Elements in reverse order:
PP
OO
FF
DD
AA
If you want to try an alphanumeric array...
//replace this line:
String[] stringArray=new String[]{"FF","PP","AA","OO","DD"};
//with this:
String[] stringArray=new String[]{"10FF","20AA","50AA"};
you gonna get the OUTPUT as follow:
50AA
20AA
10FF
source
There is a way that might be a little bit longer, but it works fine. This is a method to sort an int array descendingly.
Hope that this will help someone ,,, some day:
public static int[] sortArray (int[] array) {
int [] sortedArray = new int[array.length];
for (int i = 0; i < sortedArray.length; i++) {
sortedArray[i] = array[i];
}
boolean flag = true;
int temp;
while (flag) {
flag = false;
for (int i = 0; i < sortedArray.length - 1; i++) {
if(sortedArray[i] < sortedArray[i+1]) {
temp = sortedArray[i];
sortedArray[i] = sortedArray[i+1];
sortedArray[i+1] = temp;
flag = true;
}
}
}
return sortedArray;
}
I had the below working solution
public static int[] sortArrayDesc(int[] intArray){
Arrays.sort(intArray); //sort intArray in Asc order
int[] sortedArray = new int[intArray.length]; //this array will hold the sorted values
int indexSortedArray = 0;
for(int i=intArray.length-1 ; i >= 0 ; i--){ //insert to sortedArray in reverse order
sortedArray[indexSortedArray ++] = intArray [i];
}
return sortedArray;
}
Here is how I sorted a primitive type int array.
int[] intArr = new int[] {9,4,1,7};
Arrays.sort(nums);
Collections.reverse(Arrays.asList(nums));
Result:
[1, 4, 7, 9]
I know many answers are here, but still thinks , none of them tried using core java.
And using collection api , you will end up wasting so much memory and reseduals.
here is a try with pure core concepts , and yes this may be better way if you are more concerned about memory footprints.
int[] elements = new int [] {10,999,999,-58,548,145,255,889,1,1,4,5555,0,-1,-52};
//int[] elements = null;
if(elements != null && elements.length >1)
{
int max = 0, index = 0;
for(int i =0;i<elements.length;i++)//find out what is Max
{
if(elements[i] > max)
{
max = elements[i];
index = i;
}
}
elements[index] = elements[0];//Swap the places
elements[0] = max;
for(int i =0;i < elements.length;i++)//loop over element
{
for(int j = i+1;j < elements.length;j++)//loop to compare the elements
{
if(elements[j] > elements[i])
{
max = elements[j];
elements[j] = elements[i];
elements[i] = max;
}
}
}
}//i ended up using three loops and 2 extra variables
System.out.println(Arrays.toString(elements));//if null it will print null
// still love to learn more, please advise if we can do it better.
Love to learn from you too !

Categories