forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFillingArrays.java
More file actions
55 lines (54 loc) · 1.51 KB
/
FillingArrays.java
File metadata and controls
55 lines (54 loc) · 1.51 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// arrays/FillingArrays.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Using Arrays.fill()
import java.util.*;
import static onjava.ArrayShow.*;
public class FillingArrays {
public static void main(String[] args) {
int size = 6;
boolean[] a1 = new boolean[size];
byte[] a2 = new byte[size];
char[] a3 = new char[size];
short[] a4 = new short[size];
int[] a5 = new int[size];
long[] a6 = new long[size];
float[] a7 = new float[size];
double[] a8 = new double[size];
String[] a9 = new String[size];
Arrays.fill(a1, true);
show("a1", a1);
Arrays.fill(a2, (byte)11);
show("a2", a2);
Arrays.fill(a3, 'x');
show("a3", a3);
Arrays.fill(a4, (short)17);
show("a4", a4);
Arrays.fill(a5, 19);
show("a5", a5);
Arrays.fill(a6, 23);
show("a6", a6);
Arrays.fill(a7, 29);
show("a7", a7);
Arrays.fill(a8, 47);
show("a8", a8);
Arrays.fill(a9, "Hello");
show("a9", a9);
// Manipulating ranges:
Arrays.fill(a9, 3, 5, "World");
show("a9", a9);
}
}
/* Output:
a1: [true, true, true, true, true, true]
a2: [11, 11, 11, 11, 11, 11]
a3: [x, x, x, x, x, x]
a4: [17, 17, 17, 17, 17, 17]
a5: [19, 19, 19, 19, 19, 19]
a6: [23, 23, 23, 23, 23, 23]
a7: [29.0, 29.0, 29.0, 29.0, 29.0, 29.0]
a8: [47.0, 47.0, 47.0, 47.0, 47.0, 47.0]
a9: [Hello, Hello, Hello, Hello, Hello, Hello]
a9: [Hello, Hello, Hello, World, World, Hello]
*/