When to Use LinkedList Over ArrayList in Java

Paul Richard
Updated on 30-Jul-2019 22:30:21

3K+ Views

LinkedList should be used where modifications to a collection are frequent like addition/deletion operations. LinkedList is much faster as compare to ArrayList in such cases. In case of read-only collections or collections which are rarely modified, ArrayList is suitable.

Which One is Faster: Array or List in Java

Moumita
Updated on 30-Jul-2019 22:30:21

906 Views

The array is faster in case of access to an element while List is faster in case of adding/deleting an element from the collection.

Apply AUTO INCREMENT to a Column

George John
Updated on 30-Jul-2019 22:30:21

180 Views

AUTO_INCREMENT means that the column will get the value automatically. To illustrate it we have created a table ‘employees’ as follows − mysql> Show Create Table employees\G *************************** 1. row *************************** Table: employees Create Table: CREATE TABLE `employees` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(35) DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec) From the above result set, we can see that column id is given the auto-increment option. Now, when we will insert the value in Name ... Read More

Functions of Index Server in SAP HANA System

Anil SAP Gupta
Updated on 30-Jul-2019 22:30:21

545 Views

Index Server is heart of SAP HANA system and is responsible for processing all SQL statements sent to HANA database. This server contains SQL/MDX Processing engine that is responsible to process and analyze data in HANA db.Index Server also contains Persistence layer for scalability and restoration of the system. In case of system failure, power failure or database corruption, Persistence layer is responsible for the restoration of HANA system to last save point.When you are running complex and large calculations, and there is a system failure Persistence layer is used to ensure that transactions are either fully executed or complete ... Read More

What Does the Method addFirst(E e) Do in Java

V Jyothi
Updated on 30-Jul-2019 22:30:21

233 Views

The addFirst(E e) method of the class java.util.LinkedList inserts the specified element at the beginning of this list.Example:public class LinkedListDemo {    public static void main(String[] args) {       LinkedList list = new LinkedList();       list.add("Hello");       list.add(2);       list.add("Chocolate");       list.add("10");       System.out.println("LinkedList:" + list);       list.addFirst("Element");       System.out.println("LinkedList:" + list);    } }Output:LinkedList:[Hello, 2, Chocolate, 10] LinkedList:[Element, Hello, 2, Chocolate, 10]

Extend Multiple Python Classes in Inheritance

Rajendra Dharmkar
Updated on 30-Jul-2019 22:30:21

486 Views

As per Python documentation ‘super’ can help in extending multiple python classes in inheritance.  It returns a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by  getattr() except that the type itself is skipped.In other words, a call to super returns a fake object which delegates attribute lookups to classes above you in the inheritance chain. Points to note:This does not work with old-style classes.You need to pass your own class and ... Read More

What Does the Method addLast(E e) Do in Java?

Sravani S
Updated on 30-Jul-2019 22:30:21

203 Views

The addLast(E e) method of the java.util.LinkedList class inserts the specified element at the end of this list.Example:import java.util.*; public class LinkedListDemo {    public static void main(String[] args) {       LinkedList list = new LinkedList();       list.add("Hello");       list.add(2);       list.add("Chocolate");       list.add("10");       System.out.println("LinkedList:" + list);       list.addLast("Element");       System.out.println("LinkedList:" + list);    } }Output:LinkedList:[Hello, 2, Chocolate, 10] LinkedList:[Hello, 2, Chocolate, 10, Element]

Returning an Array in Java

George John
Updated on 30-Jul-2019 22:30:21

241 Views

Yes, an array can be returned from a java function. See the example below − Example public class Tester { public static void main(String[] args) { int[] array = getData(); for(int i: array) { System.out.println(i); } } public static int[] getData() { int[] dataArray = {1, 2, 3, 4}; return dataArray; } } Output 1 2 3 4

What Does the Method getFirst Do in Java

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

178 Views

The getFirst() method of the class java.util.LinkedList returns the first element of the current list. Example Live Demo import java.util.*; public class LinkedListDemo { public static void main(String[] args) { LinkedList list = new LinkedList(); list.add("Hello"); list.add(2); list.add("Chocolate"); list.add("10"); System.out.println("LinkedList:" + list); System.out.println("First Element :" + list.getFirst()); } } Output LinkedList:[Hello, 2, Chocolate, 10] First Element :Hello

Remove Null Value from a String Array in Java

Jai Janardhan
Updated on 30-Jul-2019 22:30:21

4K+ Views

Following program creates an array with null values. Convert it a list with not-null values only and then get the array of that list.Exampleimport java.util.ArrayList; import java.util.List; public class Tester { public static void main(String[] args) { String[] array = {"I", null, "love", null, "Java" }; List values = new ArrayList(); for(String data: array) { if(data != null) { values.add(data); } } String[] target = values.toArray(new String[values.size()]); for(String data: target) { System.out.println(data + " "); } } }OutputI love Java

Advertisements