forked from nibnait/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListTest.java
More file actions
151 lines (119 loc) · 3.88 KB
/
ListTest.java
File metadata and controls
151 lines (119 loc) · 3.88 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package zzzTest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ListTest {
static class Person {
int age;
String name;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Person(int age) {
this.age = age;
}
@Override
public String toString() {
return "Person{" +
"age=" + age +
", name='" + name + '\'' +
'}';
}
}
public static void main(String[] args) {
List<Person> personList = new ArrayList<>();
personList.add(new Person(1));
personList.add(new Person(2));
for (Person p : personList) {
p.setName("dd");
}
System.out.println(personList.toString());
}
private void testIterator() {
List<Integer> applyIds = new ArrayList<>();
applyIds.add(123);
applyIds.add(234);
Iterator<Integer> iterator = applyIds.iterator();
while (iterator.hasNext()) {
Integer next = iterator.next();
System.out.println(next);
}
}
private void testIsEmpty() {
List<String> applyIds = null;
System.out.println(applyIds.isEmpty());
}
private String[] getStringArray(List<Integer> applyIds) {
if (applyIds!=null && applyIds.size()>0){
String[] strings = new String[applyIds.size()];
int i = 0;
for (Integer integer : applyIds) {
strings[i++] = integer.toString();
}
return strings;
}
return null;
}
private static void testList2Array() {
List<Integer> applyIds = new ArrayList<>();
applyIds.add(123);
applyIds.add(234);
String[] strings = new String[applyIds.size()];
try {
// applyIds.toArray(strings);
// final int i =applyIds.size();
// Stream<String> stringStream = applyIds.stream().map(item -> item.toString());
// String[] strArray = stringStream.toArray(item -> new String[i]);
String[] strArray = applyIds.stream().map(item -> item.toString()).toArray(item -> new String[applyIds.size()]);
System.out.println(Arrays.asList(strArray));
System.out.println("----------------------------------------------------------");
Arrays.asList(applyIds);
} catch (Exception e) {
e.printStackTrace();
}
deal(strings);
}
private static void deal(String... str) {
System.out.println(str.toString());
}
private static void testDistince() {
List<String> fatherList = new ArrayList<>();
fatherList.add("快餐便当");
fatherList.add(null);
System.out.println(fatherList.toString());
List<String> unique = fatherList.stream().distinct().collect(Collectors.toList());
System.out.println(unique);
}
static class SponsorTypeDto{
private int sourceId;
private int sourceCount;
public SponsorTypeDto(int sourceId, int sourceCount) {
this.sourceId = sourceId;
this.sourceCount = sourceCount;
}
public int getSourceId() {
return sourceId;
}
public void setSourceId(int sourceId) {
this.sourceId = sourceId;
}
public int getSourceCount() {
return sourceCount;
}
public void setSourceCount(int sourceCount) {
this.sourceCount = sourceCount;
}
}
}