1. Enhanced For Loop:
The main advantage of the for-each loop is that it eliminates the possibility of bugs and makes the code more readable. It is known as the for-each loop because it traverses each element one by one.
Syntax:
for(data_type variable : array | collection){
//body of for-each loop
}
Example:
class ForEachExam{
public static void main(String args[]) {
int arr[]={1,3,14,4};
for(int i:arr){
System.out.println(i);
} } }
2. Comparable Interface:
Java Comparable interface is used to order the objects of the custom-defined class. This interface is found in java.lang package and contains only one method named compareTo(Object). It provides a single sorting sequence only, i.e., you can sort the elements on the basis of single data member only.
Lists (and arrays) of objects that implement Comparable interface can be sorted automatically by Collections.sort (and Arrays.sort).
Using Comparable interface, we can sort the elements of:
Syntax:
public interface
Comparable<T>
{
public
int compareTo(T o);
}
Example:
Student.java
class Student implements Comparable<Student>{
int rollno;
String name;
int age;
Student(int rollno,String name,int age){
this.rollno=rollno;
this.name=name;
this.age=age;
}
public int compareTo(Student st){
if(age==st.age)
return 0;
else if(age>st.age)
return 1;
else
return -1;
}
}
Main Class to test:
TestSort1.java
import java.util.*;
public class TestSort1 {
public static void main(String args[]){
ArrayList<Student> al=new ArrayList<Student>();
al.add(new Student(101,"Vijay",23));
al.add(new Student(106,"Ajay",27));
al.add(new Student(105,"Jai",21));
Collections.sort(al);
for(Student st:al){
System.out.println(st.rollno+" "+st.name+" "+st.age);
}
}
}
4. Differences between arrays and collections
5. Collection Framework

Main Types are:
1. List
Lists represents an ordered
collection of elements. Using lists, we can access elements by
their integer index (position in the list), and search for elements
in the list. index start with 0, just like an
array.
Some useful classes which implement List interface
are – ArrayList,
CopyOnWriteArrayList, LinkedList,
Stack and Vector.
2. Set
Sets represents a collection of sorted elements. Sets do not allow the duplicate elements. Set interface does not provides no guarantee to return the elements in any predictable order; though some Set implementations store elements in their natural ordering and guarantee this order.
Some useful classes which implement Set interface
are – ConcurrentSkipListSet,
CopyOnWriteArraySet, HashSet,
LinkedHashSet and TreeSet.
3. Map
The Map interface enable us to store data in key-value pairs (keys should be immutable). A map cannot contain duplicate keys; each key can map to at most one value.
The Map interface provides three collection views, which allow a map’s contents to be viewed as a set of keys, collection of values, or set of key-value mappings. Some map implementations, like the TreeMap class, make specific guarantees as to their order; others, like the HashMap class, do not.
Some useful classes which implement Map interface
are – ConcurrentHashMap,
ConcurrentSkipListMap, EnumMap,
HashMap, Hashtable,
IdentityHashMap, LinkedHashMap,
Properties, TreeMap
Describe the operation of the enhanced for loop and explain why it’s especially useful with arrays....
We learn arrays (and Arrays class) in Chapter 10 and ArrayList collection in Chapter 14. This assignment asks you to re-do Assignment 4 by using arrays and ArrayList collections to deliver exactly the same output. The input also stays the same, which are two argument values entered at the command line when 'java' command is issued. With the use of these data structures that help to store data in certain way, you are not going to print each character immediately...
Questions 1. How do conceptual frameworks of accounting attempt to create a theory of accounting? Describe the components of the IASB Framework and how it contributes to a theory of accounting. 2. Some people argue that there is no need for a general theory of accounting as established in a conceptual framework. They say there is no overall theory of physics. biology, botany or psychology, so there is no need for an overall theory of accounting. Furthermore, attempts to develop...
SHORT ANSWER QUESTIONS Part 1 Classes Abstraction: What is Abstraction in terms of representation? Specifically what choices does one make when creating a class that is an example of Abstraction? Encapsulation: What is encapsulation? What is information hiding? What does a public interface to a class consist of (not in the sense of actual java interfaces but what the client uses to manipulate objects of the class) What is an object of a class? What is the constructor? How do...
Problem Definition: Problem: Given an array of integers find all pairs of integers, a and b, where a – b is equal to a given number. For example, consider the following array and suppose we want to find all pairs of integers a and b where a – b = 3 A = [10, 4, 6, 16, 1, 6, 12, 13] Then your method should return the following pairs: 4, 1 15, 12 13, 10 A poor solution: There are...
Zipcar: “It’s Not About Cars—It’s About Urban Life” Imagine a world in which no one owns a car. Cars would still exist, but rather than owning cars, people would just share them. Sounds crazy, right? But Scott Griffith, CEO of Zipcar, the world’s largest car-share company, paints a picture of just such an imaginary world. And he has nearly 800,000 passionate customers—or Zipsters, as they are called—who will back him up. Zipcar specializes in renting out cars by the hour...
Amazon to Competition: We Will Crush You! Amazon to Employees: We Will Churn You! Globally, Amazon is one of the largest and most successful companies in any industry. Technological innovation has contributed to its success, as has its employee acquisition practices, which are exceptionally high. The question is what has allowed this company to thrive and maintain its success? This activity is important because it shows how companies like Amazon hire based on personality and individual differences. Such companies place...
what discuss can you make about medicalization and chronic
disease and illness?
Adult Lealth Nursing Ethics mie B. Butts OBJECTIVES After reading this chapter, the reader should be able to do the following: 1. Explore the concept of medicalization as it relates to the societal shift away from physician predominance of the 1970s. 2. Differentiate among the following terms: compliance, noncompliance, adherence, nonadherence, and concordance. 3. Examine cultural views with regard to self-determination, decision making, and American healthcare professionals' values...
I need help with my very last assignment of this term
PLEASE!!, and here are the instructions: After reading Chapter Two,
“Keys to Successful IT Governance,” from Roger Kroft and Guy
Scalzi’s book entitled, IT Governance in Hospitals and Health
Systems, please refer to the following assignment instructions
below.
This chapter consists of interviews with executives
identifying mistakes that are made when governing healthcare
information technology (IT). The chapter is broken down into
subheadings listing areas of importance to understand...
please read instructions on the first picture and follow
it
Discussion Board: Chapter 1 Due: Jun 28, 2019 at 11:59 PM Please read the article titled Evolution of Operations Planning and Control: from production to supply chains In at least three paragraphs, describe how and why the focus of operations planning and control has changed over time. While one might argue that answers consisting of sentences quoted from articles do not represent plagiarism, I do not consider them acceptable, and...
please read instructions on the first picture and follow
it
Discussion Board: Chapter 1 Due: Jun 28, 2019 at 11:59 PM Please read the article titled Evolution of Operations Planning and Control: from production to supply chains In at least three paragraphs, describe how and why the focus of operations planning and control has changed over time. While one might argue that answers consisting of sentences quoted from articles do not represent plagiarism, I do not consider them acceptable, and...