How to make a Java array List with different ints and arrayList

Question!

I know this may sound very silly but this is my problem.

I want a List of people. Where each person has following information about them.

  1. Number of fingers they have (int)
  2. Ward numbers they have been so far (it's a list of ints),
  3. Number of days they have been admitted in hospital (int)

I have no idea what to do here. I know how to make 2d array list of ints but the problem is that list of ward number messes everything up.

Thanks in advance,



Answers

Create a Person bean class

public class Person {
  private int fingers;
  private int days;
  private List<Integer> wardNumbers;
  //getter setters

}

And create a List<Person> patientList= new ArrayList<Person>

So you can store the details as person wise. Or

Create a Map<String,Person> patientMap = new HashMap<String,Person> So you can get the person wise details by patientMap.get("personName");

Update(doesn't recommend) for your restriction(as per comment) :

/**All information**/
List<Object> personInfo = new ArrayList<Object>();

/**Ward Number**/
List<Integer> wardNum = new ArrayList<Integer>();
wardNum.add(25);
wardNum.add(55);

personInfo.add(5);  //days
personInfo.add(6);  //fingers

personInfo.add(wardNum); //ward number

Map<String,List<Object>> patientMap = new HashMap<String,List<Object>>();
//Store
patientMap.put("patient1", personInfo);

//Retrieve
System.out.println(patientMap.get("patient1").get(0));//days
System.out.println(patientMap.get("patient1").get(1));//fingers
System.out.println(patientMap.get("patient1").get(2));//Ward Number
By : Sam


Here is the general idea how to use EventWaitHandles. You need to Reset it before doing the work, and Set it when you are done.

In the example below I have made the ResetEvent property static, but I suggest you pass the instance somehow instead, I just could not do it without more details about your architecture.

class Login
{
     private Thread performThread;
     public static ManualResetEvent ResetEvent { get; set; }
     public bool Login(Userinfo)
     {
        // do tasks like authenticate
        if(authenticationValid)
        {
            PerformLoginAsyncThread(UserInfo);
            //continue to homepage
        }
    }   

    private void PerformLoginAsyncThread(UserInfo)
    {
        ResetEvent.Reset();
        performThread = new Thread(() => 
        {
            //do stuff
            ResetEvent.Set();
        });
        performThread.Start();
    }
}

class HomePage
{
    public void OnClickFindProduct
    {
        bool finishedPostLoginThread = Login.ResetEvent.WaitOne(8000);
        if(finishedPostLoginThread)
        {
            // proceed to Find Product page
        }
        else
        {
            //If taking more than 8 seconds, throw message and exit app
        }
    }
}
By : slawekwin


I don't have the privalage to comment but you can use the required field as follows

 <input type="radio" name="question-1-answers" id="question-1-answers-A" value="A" required=true />

using this way the user will have to click all the required fields before submitting a form.



This video can help you solving your question :)
By: admin