in Education by
Which is better in terms of performance for iterating an array? (a) for(int i=0; i<100; i++) (b) for(int i=99; i>=0; i–) (c) for(int i=100; i<0; i++) (d) for(int i=99; i>0; i++) I had been asked this question in a job interview. Origin of the question is Coding best practices topic in section Autoboxing & Miscellaneous of Java Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Correct option is (b) for(int i=99; i>=0; i–) The best I can explain: reverse traversal of array take half number cycles as compared to forward traversal. The other for loops will go in infinite loop.

Related questions

0 votes
    Which is better in terms of performance for iterating an array? (a) for(int i=0; i=0; i-) ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    Which of the below is an incorrect annotation with respect to JUnits? (a) @Test (b) @BeforeClass (c) @Junit ... & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of the following is not an inheritance mapping strategies? (a) Table per hierarchy (b) Table per ... Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of the following is not an advantage of using Hibernate Query Language? (a) Database independent (b) ... Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    JUnits are used for which type of testing? (a) Unit Testing (b) Integration Testing (c) System Testing (d) ... & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which jar provides FileUtils which contains methods for file operations? (a) file (b) apache commons (c) ... Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of the following is a best practice to measure time taken by a process for execution? (a) System. ... & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    What is Optional object used for? (a) Optional is used for optional runtime argument (b) Optional is used ... & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of the below statement about JUnit is false? (a) It is an open source framework (b) It provides an ... & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of these is not a mocking framework? (a) EasyMock (b) Mockito (c) PowerMock (d) MockJava I had ... & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of the following is not introduced with Java 8? (a) Stream API (b) Serialization (c) Spliterator (d) ... & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which is the new method introduced in java 8 to iterate over a collection? (a) for (String i : StringList) ... & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which feature of java 8 enables us to create a work stealing thread pool using all available processors at ... Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which method is used to create a directory with fileattributes? (a) Path.create() (b) Path.createDirectory() ... Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which method can be used to check fileAccessiblity? (a) isReadable(path) (b) isWritable(path) (c) ... Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
...