Look at that three point in the code, it does the heavy lifting, but what does that mean.
Class Father
{
public void foo (String.. s)
{
System.out.println ("Father:foo");
}
public void Bar (String s)
{
System.out.println ("Father:bar");
}
}
Class Son extends Father
{
public void foo (String s)
{
System.out.println ("Son:foo");
}
public void Bar (String s)
{
System.out.println ("Son:bar");
}
}
===============================================================
I don't know what that means. public void Foo (String ... s)
Best Answer
Variable group parameters. Use... , the transmission of parameters can not be transmitted, the word, can be a parallel to the transmission, can also be directly an array.
When taken in a method, S is an array, and if nothing is called, the length of S is 0. There are a few passes, S is a few of the length.
Also, more than 1.5 only supports this function.
Examples of writing:
public class Number3 {
public static void Main (string[] args) {
Printstring ();
System.out.println ("==========");
Printstring (New string[]{"I", "and", "You"});
System.out.println ("==========");
Printstring ("I", "and", "You");
}
public static void Printstring (String ... str) {
if (str.length==0) {
System.out.println ("No parameters are passed.") ");
}
for (int i = 0; i < str.length; i++) {
System.out.println (Str[i]);
}
}
}
================================================
What does this mean in Java?
2011-4-6 16:12 questioner: g882 | Views: 409 times
private void Removetempfiles (String ... fileNames) {
for (String filename:filenames) {
try {
New File (fileName). Delete ();
catch (Exception e) {
}
}
}
Where the String ... fileNames means.
2011-4-6 16:26 Best Answer
Three dots after the type (String ...)., starting with Java 5, the Java language supports a new approach to method parameters, called variable-length argument lists, whose syntax is the type heel ..., which means that the parameters accepted here are 0 to more objects of type object, or a object[]. For example, we have a method called Test (string...strings), so you can also write method test (), but you can't write test (string[] strings), which will cause a compile error, and the system prompts for a duplicate.
In use, for Test (string...strings), you can use test () directly to invoke, marked without parameters, can also be used to test ("AAA"), can also use test (new string[]{"AAA", "BBB"}).
Also, if you have both the test (string...strings) function and the test () function, we will use the test () function preferentially when we call Test (). Only if the test () function is not available, we call Test () and the program goes to test (string...strings).
Example one:
public class Ttest {
private static int A;
public static void Test (int.. a) {
for (int i=0;i<a.length;i++) {
System.out.println (A[i]);
}
}
public static void Main (string[] args) {
Ttest.test (1,2);
}
}
Case TWO:
String ... excludeproperty represents an indefinite parameter, which means that you can pass in multiple string objects when you invoke this method.
public static void Main (string[] args) {
Testing, passing in multiple parameters
Test ("Hello", "World", "13SD", "I", "Cum", "ICT");
}
public static void Test (String ... arguments) {
for (int i = 0; i < arguments.length; i++) {
System.out.println (Arguments[i]);
}
}