Posts

How To Create An Object In Java ?

In this article, you will learn how to create an object in java along with accessing instance variables and methods of a class through created object.  Let us first dive into the concepts of classes and objects. Class-  A class serves as a blueprint for creating objects. It contains properties(variables) and methods(functions) that determines the state or behaviour of an object. A class is created by declaring the keyword ‘class’ followed by the ‘name of the class’. For example: class  Cuboid { // class body } The body of the class is contained between two curly braces. Object-  An Object may be defined as the sample of a class showing state or behaviour. In simple words, an object is created from a class. CREATING A CLASS IN JAVA A class in java can be created by using the keyword class followed by the name of the class. The members of the class(properties and methods) are declared under the curly braces as shown below in the example. public cl...

How to get a value inside an ArrayList java ?

Retrieve value from ArrayList in java How to get Value from ArrayList how to add new ArrayLists and ADD value to that particular ArrayList and how to RETRIEVE the data form that list. ArrayList < ArrayList < Integer >> arrayList = new ArrayList < ArrayList < Integer >>(); ArrayList < Integer > newAL = new ArrayList < Integer >(); arrayList . add ( newAL ); newAL . add ( 1 ); newAL . add ( 2 ); newAL . clear (); System . out . println ( arrayList . get ( 0 )); //Changes persist in your arraylist So after adding ArrayList you can manipulate  newAL  as  ArrayList   stores reference  you don't need to fetch and set element from main  arrayList . To retrive data you can  Iterate (Use  ForEach Loop ) over  arrayList  or you can do following Integer List0Item1 = arrayList . get ( 0 ). get ( 1 ); //Get first element of list at 0 arrayL...