April 2012

How to Create Class in Java (Public / Non Public)

By | 2012-04-29T10:25:34+00:00 April 29th, 2012|Learn By Example|

Here we will learn how to create Class and what are the different modifiers apply to class. package com.cls; /* * Note only public, abstract & final modifiers are permitted for class */ // As below class is public it should be defined in its own file(CreateClass.java) public class CreateClass { public static void main(String [...]

Retrieve elements from arraylist in java

By | 2012-04-21T15:55:07+00:00 April 21st, 2012|Learn By Example|

There are 3 different ways we can traverse an Arraylist to fetch the element in ArrayList and perform some operation. import java.util.ArrayList; import java.util.Iterator; public class ArrayListExample { public static void main(String args[]) { // Creating an ArrayList of raw type ArrayList arrListRaw = new ArrayList(); // Creating an ArrayList of generic type ArrayList<String> arrList [...]

Creating an Arraylist of String Objects in Java

By | 2012-04-21T15:04:35+00:00 April 21st, 2012|Learn By Example|

Java ArrayList represents an automatic resizable array and used in place of array. We can not modify size of an array after creating it. ArrayList in Java is growable array. ArrayList in Java implements List interface and allow null. import java.util.ArrayList; public class ArrayListExample { public static void main(String args[]) { // Creating an ArrayList [...]

Java Array initialization

By | 2012-04-21T14:40:42+00:00 April 21st, 2012|Learn By Example|

public class JavaArrayBasic { public static void main(String args[]) { /* * Array needs to be initialized before it can be used */ int intArr[] = { 1, 2 }; int intArr1[]; // intArr1 can not be used @ this place as it has not been initialized yet /* * intArr = {1,2}; Array constants [...]