Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ask a probing question. Share an insight from having read your colleague’s posti

ID: 3851727 • Letter: A

Question

Ask a probing question. Share an insight from having read your colleague’s posting. Offer and support an opinion. Validate an idea with your own experience. Make a suggestion. Expand on your colleague’s posting. note to expert .PICK ONE or two

As we learned previously, arrays can be useful tools for sorting information. ArrayLists, however, can be used as tools for sorting information just as well. There is a useful infographic found on rapidprogramming.com that breaks down the differences between these two structures. One interesting thing to note is that while arrays have a fixed size, ArrayLists do not. Another interesting point is that ArrayLists can only store objects, whereas arrays can store any type of data so long as each element of the array contains the same data type. Above, Taisa mentioned that the Contacts app on phone is a good example of these structures. I'd like to prpose that instead of using just one of these structures, the app would use both. Each field of the contacts (name, number, email, etc.) would be placed in a separate arrays of fixed size, say 500 elements. Then, the list of all contacts would be an ArrayList. For example, assume there are three arrays for name, number and email called "nam," "pho," and "em" respectively and an ArrayList called "cont" to hold the complete contact information. The first contant in the list would be cont[0] and would hold nam[0], pho[0], and em[0].

Explanation / Answer

There are some serious faults in the proposed idea-

-ArrayList can store objects as inputs is acceptable. But when we use separate arrays for size 500 and store information like name, phone and email inside of them, there is a missing link that binds a particular contact by index, when the contact gets saved in the ArrayList.
- ArrayList accepts only one input object type to saved to a particular index location, so the proposed idea that somehow name,number and email can be simultaneously indexed at same position in ArrayList is wrong. They either needs to tied to a class to make this happen, in that case name,number and email can't be defined as arrays as they are going to saving only one entry belonging to the object values of this class.
- When let say name array gets saved in ArrayList<Object> , when we query the first element of the list by using get(0), we get the entire name array, this name array has to be assigned to array of Object[] and then element of index 0 can had by using [0] on that Object array. As can be seen below this is complex way to just save the name array entry, also we have no way of getting the number and email since already index 0 is taken up by name array.


   Object[] name=new Object[500];
       name[0]="Albert";
       name[1]="Andrew";
      
   ArrayList<Object> list=new ArrayList<Object>();
  
   Object[] x=(Object[]) list.get(0);
   System.out.println(x[0]); //Shows Albert
  

-So this whole notion that simply taking cont.get(0) would get you nam[0], pho[0], and em[0] is wrong.  
- The link between values can be established either by making a Contact class and making required entries like name, phone and email as member variables rather than an array of some predefined size.
- That way whenever we have some particular contact to save we already have all the information tied down within the scope of a class and all the requested information like name, phone number and email can be had without any queries to arrays again.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote