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. |
|
| |||||||||||
Interview Questions and Answers - Order By Newest | |||||||||||
| |||||||||||
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  data structure  linked list | |||||||||||
| |||||||||||
Ans. We can get an array out of ArrayList by using toArray() method of an array list. String a[] = arrayList.toArray(); | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  array  arraylist | |||||||||||
| |||||||||||
Ans. Synchronized List locks the whole list to provide synchronization and thread safety during the read or write operation, while, CopyOnWriteArrayList doesn’t lock the whole list during these operations. The CopyOnWriteArrayList class works according to its name i.e. copy-on-write which performs different actions for reading and write operations. For every write operation (add, set, remove, etc), it makes a new copy of the elements in the list. and for the read operations (get, iterator, listIterator, etc), it works on a different copy. So there is no additional overhead during a read operation and its read operation is faster than Collections.SynchronizedList(). Thus, COWAL is better for reading operation than Synchronized List. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  Collections.synchronizedList()  CopyOnWriteArrayList | |||||||||||
| |||||||||||
Ans. 1. Arrays don't provide any built in support for sorting searching like operation and we need to do it explicitly. 2. It can hold only homogeneous objects, 3. We have to reserve memory as no dynamic expansion allowed. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  arrays  arraylist  arrays vs arraylist Asked in 3 Companies | |||||||||||
| |||||||||||
Ans. Because it's access isn't synchronized and hence access / modification by multiple threads may lead to inconsistent state. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  fail fast  arraylist  collections | |||||||||||
| |||||||||||
Ans. ArrayLists aren't synchronized and hence doesn't allow synchronized access. As multiple threads can access an arraylist in parallel, it may result in an inconsistent state. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  vector  arraylist  list  collections Basic | |||||||||||
| |||||||||||
Ans. We can copy the elements to a Set and then find the difference of count between ArrayList and Set. As Set don't allow duplicates , they will be removed in the set. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  collections  arraylist  set | |||||||||||
| |||||||||||
Ans. Initialize an ArrayList that will hold LinkedLists i.e every element of the arraylist will be a linked list. Such collection could be used in algorithms that require first random access and then sequential traversal. For example - Storing traversal paths for a graph wherein we can start from any vertex. Implementing dictionary with each arraylist element holding staring with character and then linked list holding duplicate words. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  collections  linkedlist  arraylist | |||||||||||
| |||||||||||
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  Arraylist  linkedlist  queue  collections | |||||||||||
| |||||||||||
This question was recently asked at 'Ancestry'.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  internal implementation of linkedlist Asked in 1 Companies | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
| |||||||||||