• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can someone define the type of String constructor used in the following statement?  RSS feed

 
Papi Escobar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for (String jarfilename : filenameSet) {
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

No strings are created in that statement. The strings should already be created and placed in the set beforehand. The for loop simply loops through the collection with the iterator.

Henry
 
Papi Escobar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So this is a String set? Can you explain the string parameters in the statement?
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name filenameSet implies that this is a set of Strings that represent names of files.

However, assuming that this fragment of code compiles, you can only be sure that filenameSet is of type Iterable<String> or String[].

Read this tutorial or this blog entry for more information.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Papi Escobar wrote:So this is a String set? Can you explain the string parameters in the statement?


There are no parameters in that statement. It's a for loop that declares a string reference -- that will be set to each element of the collection per iteration.

Henry
 
Papi Escobar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the other part of the code referenced in the statement. Can you explain what the Set parameters are for the String? Can you pass multiple parameters for the String in addition to filenameSet? If so How?

public static void writehtmltable(Set<String> filenameSet) {
if (filenameSet == null)
return;
 
Papi Escobar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Papi Escobar wrote:So this is a String set? Can you explain the string parameters in the statement?


There are no parameters in that statement. It's a for loop that declares a string reference -- that will be set to each element of the collection per iteration.

Henry


Ok I understand now thank you for the clarification.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!