26. Consider the following code segment. String[] names1 = {"Joe","Deb","Tom","Ann","Bob", "Sue"}; ArrayList names2 = new ArrayList(); for (int k = 0; k

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

questions are in the pics. thanks!

26. Consider the following code segment.
String names1 =
ArrayList<String> names2 = new ArrayList<String>();
for (int k = 0; k< names1.length; k++)
names2.add(names1[k]);
Which of the following describes the the behavior of the code segment?
(A) The code segment tries to copy every element of the names1 array into the
names2 array. The code is not correct,
because the size() method should be used.
(B) The code segment copies every element of the names2 array into the names1
array.
{"Joe","Deb","Tom","Ann","Bob","Sue"};
(C) The code segment copies every element of the names1 array into the names2
array.
(D) The code segment tries to copy every element of the names2 array into the
names1 array. The code is not correct. Not
every element of the array is copied.
(E) The code does not compile, method length() is lacking a set of parentheses.
26. Which of the following describes the the behavior of the code segment?
O A
B
O D
E
Transcribed Image Text:26. Consider the following code segment. String names1 = ArrayList<String> names2 = new ArrayList<String>(); for (int k = 0; k< names1.length; k++) names2.add(names1[k]); Which of the following describes the the behavior of the code segment? (A) The code segment tries to copy every element of the names1 array into the names2 array. The code is not correct, because the size() method should be used. (B) The code segment copies every element of the names2 array into the names1 array. {"Joe","Deb","Tom","Ann","Bob","Sue"}; (C) The code segment copies every element of the names1 array into the names2 array. (D) The code segment tries to copy every element of the names2 array into the names1 array. The code is not correct. Not every element of the array is copied. (E) The code does not compile, method length() is lacking a set of parentheses. 26. Which of the following describes the the behavior of the code segment? O A B O D E
27. There are two loop structures in Java that can be used with arrays:
1. There is the traditional for loop
that accesses specified array elements using the index of each element.
2. There is the newer
enhanced for loop structure that accesses element of the array without using
an index.
Which of the
following are advantages of using the traditional, index access, loop?
It is simpler to use with multi-dimensional arrays.
It is a read/write loop.
It can access specified array elements.
It has an easy-to-use initializer list to add a group of element to a new array.
All of the above
28. There are two loop structures in Java that can be used with arrays:
1. There is the traditional for loop
that accesses specified array elements using the index of each element.
2. There is the newer
enhanced for loop structure that accesses element of the array without using
an index.
Which of the
following are advantages of using the newer, enhanced for loop?
It requires less program code.
There is much less concern that the code creates an IndexOutOfBoundsException
It is guaranteed that every element of the array is accessed.
It can be used with data structures that have no index access.
O All of the above
Transcribed Image Text:27. There are two loop structures in Java that can be used with arrays: 1. There is the traditional for loop that accesses specified array elements using the index of each element. 2. There is the newer enhanced for loop structure that accesses element of the array without using an index. Which of the following are advantages of using the traditional, index access, loop? It is simpler to use with multi-dimensional arrays. It is a read/write loop. It can access specified array elements. It has an easy-to-use initializer list to add a group of element to a new array. All of the above 28. There are two loop structures in Java that can be used with arrays: 1. There is the traditional for loop that accesses specified array elements using the index of each element. 2. There is the newer enhanced for loop structure that accesses element of the array without using an index. Which of the following are advantages of using the newer, enhanced for loop? It requires less program code. There is much less concern that the code creates an IndexOutOfBoundsException It is guaranteed that every element of the array is accessed. It can be used with data structures that have no index access. O All of the above
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Fundamentals of Multithreaded Algorithms
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education