Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'String...' mean? [duplicate]

In the code:

public interface ProductInterface {

    public List<ProductVO> getProductPricing(ProductVO product, ProductVO prodPackage, String... pricingTypes) throws ServiceException;

}

What does

String... pricingTypes

mean? What type of construct is this?

like image 961
David Silva Avatar asked Aug 11 '13 20:08

David Silva


People also ask

What is duplicate string?

Java 8Object Oriented ProgrammingProgramming. The duplicate characters in a string are those that occur more than once. These characters can be found using a nested for loop. An example of this is given as follows − String = Apple. In the above string, p is a duplicate character as it occurs more than once.

Can string have duplicates?

To find the duplicate character from the string, we count the occurrence of each character in the string. If count is greater than 1, it implies that a character has a duplicate entry in the string. In above example, the characters highlighted in green are duplicate characters.

How do you check if there is a duplicate in a string?

As an aside, when you are comparing Strings, you should use . equals() instead of == . Show activity on this post. I.e. if the number of distinct characters in the string is not the same as the total number of characters, you know there's a duplicate.


1 Answers

It is called varargs. It works for any type as long as it's the last argument in the signature.

Basically, any number of parameters are put into an array. This does not mean that it is equivalent to an array.

A method that looks like:

void foo(int bar, Socket baz...)

will have an array of Socket (in this example) called baz.

So, if we call foo(32, sSock.accept(), new Socket()) we'll find an array with two Socket objects.

Calling it as foo(32, mySocketArray) will not work as the type is not configured to take an array. However, if the signature is a varargs of arrays you can pass one or more arrays and get a two-dimensional array. For example, void bar(int bar, PrintStream[] baz...) can take multiple arrays of PrintStream and stick them into a single PrintStream[][].

Oddly enough, due to the fact that arrays are objects, Object... foo can take any number of arrays.

like image 106
nanofarad Avatar answered Oct 16 '22 20:10

nanofarad