Pairs - Hacker Rank Program

Problem Statement
Given N integers, count the number of pairs of integers whose difference is K.
Input Format
The first line contains N and K.
The second line contains N numbers of the set. All the N numbers are unique.
Output Format
An integer that tells the number of pairs of integers whose difference is K.
Constraints:
N105
0<K<109
Each integer will be greater than 0 and at least K smaller than 2311.
Sample Input #00:
5 2  
1 5 3 4 2  
Sample Output #00:
3
Sample Input #01:
10 1  
363374326 364147530 61825163 1073065718 1281246024 1399469912 428047635 491595254 879792181 1069262793 
Sample Output #01:
0

MY SOLUTION:
 
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
    public static void main(String[] args)
{
        Scanner s=new Scanner(System.in);
        int n,k,count=0;
        int i;
        n=s.nextInt();
        k=s.nextInt();
        long[] a=new long[n];
        for(i=0;i<n;i++)
            {
            a[i]=s.nextLong();
           }
       Arrays.sort(a);
        int length=n-1;
        while(length!=0)
        {
         for(i=length-1;i>=0;i--)
         {
            
            if(Math.abs(a[length]-a[i])==k)
            {
                count++;
            break;
            }
        
         }
            length--;
        }
        System.out.println(count);
    }
}
 

Convert resultset object to list of map

Convert the resultset object to list of map In some cases, while we doing API automation, we need to fetch the value from the DB and hav...