FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-code-example/Generic/add_arrays.java at master · cherkavi/java-code-example · GitHub
cherkavi
/
java-code-example
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
0
Code
Issues
0
Pull requests
42
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-code-example
/
Generic
/
add_arrays.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
43 lines (42 loc) · 1.11 KB
Breadcrumbs
java-code-example
/
Generic
/
add_arrays.java
Copy path
File metadata and controls
executable file
·
43 lines (42 loc) · 1.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
private
static
<
T
>
T
[]
addArrays
(
T
[]
one
,
T
[]
two
){
if
((
one
!=
null
)&&(
two
!=
null
)){
one
.
getClass
();
T
[]
returnValue
=
null
;
if
(
one
.
length
>
0
){
returnValue
=(
T
[])
Array
.
newInstance
((
one
[
0
]).
getClass
(),
one
.
length
+
two
.
length
);
}
else
{
if
(
two
.
length
>
0
){
returnValue
=(
T
[])
Array
.
newInstance
((
two
[
0
]).
getClass
(),
one
.
length
+
two
.
length
);
}
else
{
return
null
;
}
}
for
(
int
counter
=
0
;
counter
<
one
.
length
;
counter
++){
returnValue
[
counter
]=
one
[
counter
];
}
for
(
int
counter
=
0
;
counter
<
two
.
length
;
counter
++){
returnValue
[
counter
+
one
.
length
]=
two
[
counter
];
}
return
returnValue
;
}
else
{
if
((
one
==
null
)&&(
two
==
null
)){
return
null
;
}
else
{
if
(
one
==
null
){
return
two
;
}
else
{
// only two has null
return
one
;
}
}
}
}
public
static
void
main
(
String
[]
args
){
Integer
[]
one
=
new
Integer
[]{
1
,
2
,
3
,
4
};
Integer
[]
two
=
new
Integer
[]{
5
,
6
,
7
,
8
};
Integer
[]
three
=
addArrays
(
one
,
two
);
for
(
int
counter
=
0
;
counter
<
three
.
length
;
counter
++){
System
.
out
.
print
(
counter
+
":"
+
three
[
counter
]+
" "
);
}
System
.
out
.
println
();
}
Back
|
FazBrowse Home
|
New Git URL