Skip to content

Commit 2819b31

Browse files
author
eugenp
committed
simple collections conversion work
1 parent d06f8f8 commit 2819b31

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

core-java/src/test/java/org/baeldung/java/collections/JavaCollectionConversionUnitTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,40 @@ public final void givenUsingCommonsCollections_whenSetConvertedToArrayOfPrimitiv
104104
final int[] primitiveTargetArray = ArrayUtils.toPrimitive(targetArray);
105105
}
106106

107+
// Set -> List; List -> Set
108+
109+
public final void givenUsingCoreJava_whenSetConvertedToList_thenCorrect() {
110+
final Set<Integer> sourceSet = Sets.newHashSet(0, 1, 2, 3, 4, 5);
111+
final List<Integer> targetList = new ArrayList<>(sourceSet);
112+
}
113+
114+
public final void givenUsingCoreJava_whenListConvertedToSet_thenCorrect() {
115+
final List<Integer> sourceList = Lists.newArrayList(0, 1, 2, 3, 4, 5);
116+
final Set<Integer> targetSet = new HashSet<>(sourceList);
117+
}
118+
119+
public final void givenUsingGuava_whenSetConvertedToList_thenCorrect() {
120+
final Set<Integer> sourceSet = Sets.newHashSet(0, 1, 2, 3, 4, 5);
121+
final List<Integer> targetList = Lists.newArrayList(sourceSet);
122+
}
123+
124+
public final void givenUsingGuava_whenListConvertedToSet_thenCorrect() {
125+
final List<Integer> sourceList = Lists.newArrayList(0, 1, 2, 3, 4, 5);
126+
final Set<Integer> targetSet = Sets.newHashSet(sourceList);
127+
}
128+
129+
public final void givenUsingCommonsCollections_whenListConvertedToSet_thenCorrect() {
130+
final List<Integer> sourceList = Lists.newArrayList(0, 1, 2, 3, 4, 5);
131+
132+
final Set<Integer> targetSet = new HashSet<>(6);
133+
CollectionUtils.addAll(targetSet, sourceList);
134+
}
135+
136+
public final void givenUsingCommonsCollections_whenSetConvertedToList_thenCorrect() {
137+
final Set<Integer> sourceSet = Sets.newHashSet(0, 1, 2, 3, 4, 5);
138+
139+
final List<Integer> targetList = new ArrayList<>(6);
140+
CollectionUtils.addAll(targetList, sourceSet);
141+
}
142+
107143
}

0 commit comments

Comments
 (0)