Core Java - Interview Questions and Answers for 'List' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   
 Q41. What are the ways to get the values from list ?Data Structure
Ans. list.get(index);

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     list     Asked in 1 Companies


 Q42. When do you use a Vector?Core Java
 This question was recently asked at 'adobe'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     vector  collections  list     Asked in 1 Companies


 Q43. Can we modify a list while iterating it ?Core Java
Ans. No,we cannot.I t will give concurrentModificationExceptin error. It can be resolved by using ConcurrentClasses like ConcurrentHashMap,CopyOnWriteArrayList,BlockingQueue etc which are fail-safe and wont give exception.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections  list  iterator     Asked in 1 Companies      basic


 Q44. Which of the following - arrays or LinkedList allow elements to be accessed using index and how ? Data Structure
Ans. Arrays allows elements to be accessed directly using the index.

As Array elements are stored in continuous memory locations it's very easy to find the memory address of any element using the formula as following

Memory Address of Array start or index 0 + ( Size of array element * Index )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  linkedlist


 Q45. Write code to see if a Linked List has cycle in it ?

or

Write code using Floyd Algorithm to see if a linked list has cycle in it ? What is it's comlexity ?
Algorithm
Ans. public class LinkedList {

Node start = null;
Node head = null;

class Node {
Integer body;
Node nextNode;

Node(Integer value) {
body = value;
}
}

public static void main(String[] args) {
LinkedList ll = new LinkedList();

ll.addNodeToEnd(5);
ll.addNodeToEnd(10);
ll.addNodeToEnd(15);

ll.traverse();

if(checkIfLoop(l1)){
System.out.println("There is a Loop");
} else {
System.out.println("No Loop");
}
}

private boolean checkifLoop(Test l1) {
Node slow = start;
Node fast = start;
Node faster = start;
      
while(slow != null ) {
fast = slow.nextNode;
faster = fast.nextNode;
if(slow == fast || slow == faster) {
return true;
}
slow = slow.nextNode;
}
      
return false;
}

}

Complexity of this algorithm is O(n)

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     LinkedList  Cyclic LinkedList


 Q46. What can we do if we need to retrieve Fibonacci value at a particular index faster ? Can we use Linked List ?Data Structure
 This question was recently asked at 'Canopy Tax'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     LinkedList     Asked in 1 Companies


 Q47. Difference between Arrays and LinkedList ?Data Structure
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays vs linkedlist


 Q48. Detect a loop in a linked listData Structure
Ans. Work with two pointers on the linked list - a slow pointer (increments by one node) and a fast pointer (increments by two nodes). If both of these pointers meet at the same node, then there is a cycle in the linked list. Otherwise, no cycle.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     linkedlist     Asked in 1 Companies


 Q49. Difference between List and ArrayList ?Core Java
Ans. List is an interface whereas ArrayList is an implementation of List.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     list  arraylist  list vs arraylist  difference between  collections     Asked in 2 Companies      basic


 Q50. What is the default size of list ? How it is growable ?Core Java
Ans. Default size is 10.
Regard how size will increase.

Inside add() method there is one method called ensureCapacity() which will check list has enough size available.

This ensureCapacity() method if found size of list need to increase then it will call grow() method which will create new list of extra size and copy existing list data to new one and return.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     list  default size of list     Asked in 1 Companies


 Q51. difference between ArrayList and array ?Core Java
Ans. ArrayList is a variable length collection class whereas arrays are fixed length primitive structure.

We can use generics with arraylist but not with arrays.

We can store primitive data types within arrays but can't with ArrayList. In ArrayList that needs to be converted to Wrapper objects.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arraylist  arrays  collection classes  collections      basic        frequent


 Q52. Difference between ArrayList and HashSet ?Core Java
Ans. ArrayList is a list , i.e an implementation of List interface whereas HashSet is a Set and an implementation of Set interface.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arraylist  hashset


 Q53. How can we create an arraylist of unique values ?Core Java
Ans. We can put the value in a set to enforce uniqueness and then dum those value into an arraylist.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arraylist  design  collections


 Q54. What is the difference between closing and completing the observer / listener ?Angular
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     observer   listener


 Q55. What will be the output of exceuting main method ?

public static void main(String[] args){
      List list = new ArrayList();
      list.add(1);
      list.add(2);
      list.add(3);
      System.out.println(list);
   }
Core Java
a. 1,2,3
b. Order cannot be determined
c. compilation error
d. 3,2,1

Ans.a. 1,2,3

 Q56. What will be the output of this code

ArrayList list = new LinkedList();
list.add(3);
list.add(2);
list.add(1);
System.out.println(list);
Core Java
a. 1,2,3
b. 3,2,1
c. Order cannot be determined
d. Compilation Error

Ans.d. Compilation Error

previous 30   

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: