Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this code. But when i run it, it says Exception in thread main java.lang.NullPointerException. Can someone please fix this and print the updated

I have this code. But when i run it, it says Exception in thread "main" java.lang.NullPointerException. Can someone please fix this and print the updated fixed code solution?

import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.lang.instrument.Instrumentation; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList;

public class ArrayLinkedListExamples { private static Instrumentation instrumentation; public static void main(String args[]) throws IOException {

// Creating an empty Array and Linked list ArrayList arraylist = new ArrayList(); LinkedList linkedlist = new LinkedList();

BufferedReader br = new BufferedReader(new FileReader("C:midData.csv"));

String strLine; //Read File Line By Line while (!((strLine = br.readLine()) == null)) { arraylist.add(strLine); linkedlist.add(strLine); } br.close();

long size = instrumentation.getObjectSize(arraylist); System.out.println("Bytes used by Arraylist object: " + size); size = instrumentation.getObjectSize(linkedlist); System.out.println("Bytes used by Arraylist object: " + size);

long startl = 0, countl = 0; for (Iterator it = linkedlist.iterator(); it.hasNext();) { String str = it.next(); String [] arrOfStr = str.split(","); if(Integer.parseInt(arrOfStr[1]) > 55){ countl++; } }

long timel = System.nanoTime() - startl; long starta = 0, counta = 0; for (Iterator it = arraylist.iterator(); it.hasNext();) { String str = it.next(); String [] arrOfStr = str.split(","); if(Integer.parseInt(arrOfStr[1]) > 55){ counta++; } } long timea = System.nanoTime() - starta; System.out.println("Count and CPU time for LinkedList:"); System.out.println("Count of the number of records that have the Age > 55:"+countl); System.out.println("The CPU time used for this operation in nano second:"+timel); System.out.println("Count and CPU time for ArrayList:"); System.out.println("Count of the number of records that have the Age > 55:"+counta); System.out.println("The CPU time used for this operation in nano second:"+timea); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

4 Name four appraisal methods.

Answered: 1 week ago

Question

8 What problems can occur with appraisal?

Answered: 1 week ago