time complexity ..in int and long (java)..plz help

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
public class TurboSort3 {

	public static void main(String args[]) throws IOException {
		BufferedReader br= new BufferedReader( new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(
				new BufferedWriter(
						new OutputStreamWriter(System.out)));
		String s= br.readLine();
		Integer test = Integer.parseInt(s);	
		long[] c= new long[test];
		int i=0;
		while(test>0) {
			int n = Integer.parseInt(br.readLine());
			c[i]=n;
			i++;
			test--;
		}
			
	Arrays.sort(c);
	
		for(int j=0;j<c.length;j++){
			pw.println(c[j]);
			}
		
		pw.close();
		
		}

}

This code takes time=5.29secā€¦and when I am using ā€œintā€ instead of ā€˜longā€™ for the array ā€˜cā€™ā€¦that takes time = 10.01 secā€¦why is it taking different time reading ā€˜longā€™ and ā€˜intā€™ā€¦?? plz explainā€¦

are you sure???

see these two submissionsā€¦intā€¦long!!!

int - 5.21

long - 5.30

that is not a huge diff!!!

1 Like

yeahā€¦I checked it outā€¦In my program when I wrote ā€˜Integerā€™ not int for the array ā€˜cā€™ā€¦then it took 9.67 secā€¦ http://www.codechef.com/viewsolution/2299592

Integer is a class. Something more than just int. It is a wrapper around an int.

Being a simple variable has its advantages over being an object of any class. I must anticipate that this must be the reason for the slow down, when using Integer. As @kunal361 points out, there is not much difference when using int and long.

1 Like

okā€¦thanks for the infomationā€¦