forked from slgobinath/Java-Helps-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintArray.java
More file actions
26 lines (24 loc) · 733 Bytes
/
PrintArray.java
File metadata and controls
26 lines (24 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.StringJoiner;
/**
* Example utility interface with a static method.
* You need Java 8 to compile and run this code.
* Static methods in interfaces are introduced in Java 8.
* The StringJoiner class also introduced in Java 8 to join Strings efficiently.
*
* @author L.Gobinath
*/
public class PrintArray {
public static void main(String[] args) {
String[] arr = {"Java", "C++", "C", "Python", "PHP"};
Printer.print(arr);
}
}
interface Printer {
public static void print(String[] array) {
StringJoiner joiner = new StringJoiner(", ", "[", "]");
for (String str : array) {
joiner.add(str);
}
System.out.println(joiner.toString());
}
}