A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Login successful program code using list of users in ArrayList

The following steps to create program of Login successful :


Step 1. import the ArrayList class inside the current class;

import java.util.ArrayList;


step 2. create object of the ArrayList class inside the current class


 ArrayList  mylist = new ArrayList();

step 3. add all the object on the list.

        mylist.add("Aman");
        mylist.add("raju");
        mylist.add("amit");
        mylist.add("chaitanya");
        mylist.add("simran");
        mylist.add("Admin");
        mylist.add("ravish");

step 4. create an validate or check method to find the admin in current list of arraylist type.


 private static boolean check(ArrayList mylist2, int i)
    {
       if(mylist2.get(i)=="Admin")
       {
           return true;
       }
       else
       {
           return false;
       }
    }


step 5. create a Boolean type datatype to check on the future flag value, to validate the user present inside the list.



 boolean flag=false;


step 6. check each index of list by using arraylist index and for loop.


        for(int i=0; i<mylist.size(); i++)
        {
            if(check(mylist,i)==true)
            {
                flag=true;
            }
               
        }


step 7. if flag value is true or false. It will provide exact and correct output on console.


        if(flag==true)
        {
            System.out.println("Login Successful");
        }
        else
        {
            System.out.println("you have forget username!");
        }


Full Program code of login successful:


import java.util.ArrayList;
class Details
{
    public static void main(String a[])
    {
        ArrayList  mylist = new ArrayList();
        mylist.add("Aman");
        mylist.add("raju");
        mylist.add("amit");
        mylist.add("chaitanya");
        mylist.add("simran");
        mylist.add("Admin");
        mylist.add("ravish");
       
        boolean flag=false;
       
        for(int i=0; i<mylist.size(); i++)
        {
            if(check(mylist,i)==true)
            {
                flag=true;
            }
               
        }
       
        if(flag==true)
        {
            System.out.println("Login Successful");
        }
        else
        {
            System.out.println("you have forget username!");
        }
    }

    private static boolean check(ArrayList mylist2, int i)
    {
       if(mylist2.get(i)=="Admin")
       {
           return true;
       }
       else
       {
           return false;
       }
    }
}

LEARN TUTORIALS

.

.