Java Reference
In-Depth Information
public static void main(String[] args)
{
GArray<String> ga = new GArray<>(10);
System.out.println("Size = "+ga.size());
ga.set(3, "ABC");
System.out.println("Size = "+ga.size());
ga.set(22, "XYZ");
System.out.println("Size = "+ga.size());
System.out.println(ga.get(3));
System.out.println(ga.get(22));
System.out.println(ga.get(20));
ga.set(20, "PQR");
System.out.println(ga.get(20));
System.out.println("Size = "+ga.size());
}
}
When you run this application, it should generate the following output:
Size = 0
Size = 4
Size = 23
ABC
XYZ
null
PQR
Size = 23
4. Modify Listing4-17 ' s CountingThreads applicationbymarkingthetwo
countingthreadsasdaemonthreads.Whathappenswhenyouruntheresult-
ing application?
5. Modify Listing4-17 's CountingThreads applicationbyaddinglogicto
stopbothcountingthreadswhentheuserpressestheEnterkey.Thedefault
mainthreadshouldcall System.in.read() priortoterminating,andas-
sign true to a variable named stopped after this method call returns.
Eachcountingthreadshouldtestthisvariabletoseeifitcontainstrueatthe
start of each loop iteration, and only continue the loop when the variable
contains false.
Search WWH ::




Custom Search