Menu

Working with list and arrayList in Java.

In this tutorial we will see a simple and small implementation of List and ArrayList using Java.

ArrayList is resize-able implementation is List type. Each ArrayList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added to an ArrayList, its capacity grows automatically.

We are writing a program where we will add some values in the ArrayList and then we will iterate on that List and print the values on console.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
package rashid.jorvee;

import java.util.ArrayList;
import java.util.List;

public class ListImpl {

 public static void main(String[] args) {
  List list=new ArrayList();
  List newlist=new ArrayList();
  newlist.add("New Delhi");
  newlist.add("9999999");
  newlist.add("1212121");
  newlist.add("Rashid");
  newlist.add("Jorvee");
  for(int i=0;i<newlist.size();i++) {
   System.out.println("At Index "+i +" List has value "+newlist.get(i));
  }

 }

}
Output:
At Index 0 List has value New Delhi
At Index 1 List has value 9999999
At Index 2 List has value 1212121
At Index 3 List has value Rashid
At Index 4 List has value Jorvee

How to check valid and invalid email address using Java?

We will see how to validate and check whether entered email ID is valid or not using Java programming. Here I am writing a simple Java code which will validate the format of email using regular expression(regex).

  1. Declare a variable with email addresses of type String[] array.
  2. Write a for loop which will iterate every item(email addresses) from your array.
  3. Create a parameterized method with return type boolean which will accept your email address and check for valid or not.
  4. Method will match the format of your email with regex: [a-zA-Z0-9._-][a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4} and return true or false.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
package rashid.jorvee;


public class ValidEmailValidator {

 public static void main(String[] args) {
  String[] emailAddresses= {"sohal@shopoo.co","adyu+@sud.com","asg_sj-@asgd.co","rashid@do.in.com","rashid.ta@rasj.com","fdh%sdfkj_@dsj.cojn"};
  for(String email : emailAddresses) {
   if(validEmail(email)) {
    System.out.println("Valid email address :" +email);
   }
   else {
    System.out.println("Invalid email address :"+email);
   }
  }
 }
 static boolean validEmail(String email) {
  return email.matches("[a-zA-Z0-9._-][a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}");
 }
}

Output:

Valid email address :vsohal@shopoo.co

Invalid email address :adyu+@sud.com
Valid email address :asg_sj-@asgd.co
Valid email address :rashid@rasj.com
Valid email address :rashid.ta@rasj.com
Invalid email address :fdh%sdfkj_@dsj.cojn

what is the meaning of color?

Does colors want to say you something and want to convey a message to you? Lets see what is the meaning of a colour which you like most?


Black          : artistic, sensitive, introvert, sophisticated, careful, luxury, sorrow, power, elegance, formality, death, evil, and mystery.



Red          : color of blood, energy, war, danger, strength, excitement, power, determination, passion, desire, and love.



Yellow          : color of shine, cheerful, pleasant, warning, playful, learning and sharing, joy, happiness, intellect, and energy.


White         : color of perfection, light, goodness, innocence, cleanliness, simplicity, purity, and virginity.


Green          : color of nature, growth, harmony, freshness, wealth, prestige and fertility.


Blue          : color of sky, trust, loyalty, wisdom, communicative, calming, confidence, intelligence, faith, truth, and heaven.Purple: color of royalty, power, nobility, luxury, spiritual, majesty, mysterious and ambition.


Orange          : youthful, fresh, enthusiasm, fascination, happiness, creativity, determination, attraction, success, encouragement, joy, and stimulation.


Brown           : organic, wholesome, simple and honest.Pink: Feminine, Sentimental, Romantic and Exciting.