Posts

Showing posts from May, 2016

Fetch elements from LinkedList

There are several methods given in the linked list to retrieve the inserted elements. Each method has its own importance. E.g. If user wants to retieve the first element from the list, it can choose among get(int index), getFirst(), element(), peek() or peekFirst() methods but there usages are different like get(int index) method provides the element from any given position(index) whereas getFirst(), element(), peek() or peekFirst() methods returns only first element from the list. Let us see the different usages of these methods: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 package net . raj . test . list ; import java.util.LinkedList ; /** * @author Raj Saxena * */ public class LinkedListRetrieveImpl { public static void main ( String ... args ) { // Declare an LinkedList LinkedList < String > list = new LinkedList <...

LinkedList Traversal In Reverse Sequential Order

LinkedList traversal can be done in two directions - Ascending and Descending The ascending traversal or normal or forward traversal can be done using iterator method provided by List interface whereas for the descending order traversal is possible using method provided by Dequeue interface. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 package net . raj . test ; import java.util.Iterator ; import java.util.LinkedList ; /** * @author Raj Saxena * */ public class LinkedListTraversalImpl { public static void main ( String [] args ) { // Declare an LinkedList LinkedList < String > list = new LinkedList <>(); // populate list list . add ( "one" ); list . add ( "two" ); list . add ( "three" ); list . add ( "four" ); list . add ( "five" ); System . out . println ( "List traversal in...

Sustainability Cloud

Image
Cloud means "Internet based computing" where various services like storage, servers and applications are available on-demand and charged as per the usage. It is basically based on the sharing of resources where the various resources which are available at same or different locations can be used by offered services which do their jobs as given. In this sense we ensure the maximum usage of resources and technology.     This concept came into picture while applying the supercomputer or high performing computers which were being used to do military and research jobs execution which needs trillions of data to be executed and stored. By using the available resources on the internet we can reduce the cost of maintainance and excution and process a large volume of data at a very little cost as compared to investing in the setup of whole infrastructure and better of all we can reuse the same infrastructure with some other job too without reinvesting.     ...

ArrayList Declaration and Assignment in one line

An ArrayList is a group of common elements. It is concrete implementation of List interface. ArrayList has ordered elements in which order they added.We can declare and assign elements to it in one line in various ways. Output: Sample ArrayList:: [one, two, three, four] Stream Arraylist:: [abc, xyz] Look at my other posts: Stack in Java Custom Stack Implementation Set Interface in Java Custom Doubly LinkedList Implementation Custom LinkedList Implementation How to fetch elements from LinkedList List Traversal How to insert elements in List How to remove element from list How to declare Linked List and Implement LinkedList Traversal In Reverse Sequential Order ArrayList in Java How to declare array list in java Some other interesting blogs: IOT and Big Data Technologies Sustainability Cloud

List Traversal

There are so many questions comes into mind when we go to the coding floor and starts writing the code for list like how to traverse the list in java? What are the different ways to traverse a list? Which is the best way? Which way needs to be followed? Here, we will try to find out the answers of these questions. There are two ways to traverse the list - forward or backward. The list has given methods like next and previous. We can iterate the list starting from a specific index too. Output : Iterating list in forward direction... one two three four five Iterating list in backward direction... five four three two one Iterating list from specified position... three four five Look at my other posts: Stack in Java Custom Stack Implementation Set Interface in Java Custom Doubly LinkedList Implementation Custom LinkedList Implementation How to fetch elements from LinkedList List Traversal How to insert elements in List How to remove element...

LinkedList Declaration

Image
An LinkedList is a group of common elements. It is concrete implementation of List and Deque interface. It permits all elements including null. Output : Original LinkedList :: [one, two, three, four, five] Look at my other posts: Stack in Java Custom Stack Implementation Set Interface in Java Custom Doubly LinkedList Implementation Custom LinkedList Implementation How to fetch elements from LinkedList List Traversal How to insert elements in List How to remove element from list How to declare Linked List and Implement LinkedList Traversal In Reverse Sequential Order ArrayList in Java How to declare array list in java Some other interesting blogs: IOT and Big Data Technologies Sustainability Cloud

Remove element from list

From the list we can remove the element in two ways. 1. Remove the element on the basis of object index or position : package net.raj.test; import java.util.ArrayList; import java.util.List; public class ArrayListImpl {     public static void main(String[] args) {         // Declare an ArrayList         List<String> list = new ArrayList<>();         list.add("one");         list.add("two");         list.add("three");         list.add("four");         list.add("five");         System.out.println("Sample ArrayList Before Removal :: " + list.toString());                 // remove the 1st element         list.remove...

List - Insertion order

 List interface keeps the order of insertion of elements i.e. the order in which the elements added to the list will remain in same order after any operation. Every addition takes the index of last inserted element plus one (last index + 1). 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 package net . raj . test ; import java.util.ArrayList ; import java.util.List ; public class ArrayListImpl { public static void main ( String [] args ) { // Declare an ArrayList List & lt ; String & gt ; list = new ArrayList & lt ;& gt ;(); list . add ( "one" ); list . add ( "two" ); list . add ( "three" ); list . add ( "four" ); System . out . println ( "Sample ArrayList 1:: " + list . toString ()); // Reuse the same object // list keeps the order list = new ArrayL...

Why I love Java...

Sometimes I feel blessed that I got the chance to work with a technology which is given the greatest flexibility in its area compared to other ones. Yes, you are right I am talking about JAVA. What is my first requirement? Run my code anywhere . Java is the one which provides the facility to write my code and run it anywhere. How can I do so? Actually, JAVA provides a very good feature of byte code which is the intermediate form of the code after compilation and this byte code is the input for the machine specific interpretor which are different for different machines.What I need to remember is to just write my code and compile it properly and rest is with JAVA. Can I learn it easily? I think this is one of the best and easy language to work on. My statement is supported by the concept of OOP i.e. Object Oriented Programming. Yes, it is based on concept of Object Oriented which takes everything as an Object in the program and change it to the Class and Methods. e.g....

ArrayList in Java

An ArrayList is a group of common elements. It is concrete implementation of List interface. ArrayList has ordered elements in which order they added. There are several methods which we will discuss here today. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package net . raj . test ; import java.util.ArrayList ; import java.util.List ; public class ArrayListImpl { public static void main ( String [] args ) { // Declare an ArrayList List < string > list = new ArrayList <>(); list . add ( "one" ); list . add ( "two" ); list . add ( "three" ); list . add ( "four" ); System . out . println ( "Sample ArrayList 1:: " + list . toString ()); } } Output: Sample ArrayList 1:: [one, two, three, four] In the above example we saw that we added few elements when print those items we saw the same order in which they added to list. It shows the basic property ...