Grouping items in a list into inner lists in java

Multi tool use
I have a function that looks up in a list
the elements which share same values in order to group them.
As a fast summary, this should be the input/output:
[A, A', B, C, B', A''] --> [[A, A', A''], [B, B'], [C]]
I do not care about order. It could also produce:
[A, A', B, C, B', A''] --> [[B, B'], [A, A', A''], [C]]
This is my Test Code to see the output samples:
class A {
private Long id;
private String name;
private Object param;
A(Long id, String name, Object param) {
this.id = id;
this.name = name;
this.param = param;
}
@Override
public String toString() {
return "{tid:" + id + ",tname:" + name + ",tparam:" + param + "}";
}
}
public class ListsTest {
private final A a1 = new A(1L, "A", 100);
private final A a2 = new A(2L, "B", 200);
private final A a3 = new A(1L, "A", 300);
private final A a4 = new A(1L, "B", 400);
@Test
public void groupByIdAndName() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupByIdAndName");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "id", "name");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3), List.of(a2), List.of(a4))));
}
@Test
public void groupById() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupById");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "id");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3, a4), List.of(a2))));
}
@Test
public void groupByName() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupByName");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "name");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3), List.of(a2, a4))));
}
}
Which outputs:
groupById
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}], [{ id:1, name:B, param:400}]]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}, { id:1, name:B, param:400}], [{ id:2, name:B, param:200}]]
groupByIdAndName
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}], [{ id:1, name:B, param:400}]]
groupByName
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}, { id:1, name:B, param:400}]]
The code I developed for it is the following:
public class Lists {
private static <T> Object getObjectFieldsHash(T obj, String... fields) throws NoSuchFieldException, IllegalAccessException {
List<Object> vals = new ArrayList<>();
for (String field: fields) {
Field f = obj.getClass().getDeclaredField(field);
f.setAccessible(true);
vals.add(f.get(obj));
}
return Objects.hash(vals);
}
public static <T> List<List<T>> groupByFields(List<T> objects, String... fields ) throws NoSuchFieldException, IllegalAccessException {
List<List<T>> result = new ArrayList<>(); // Is it possible to create same type of original List instead of always ArrayList?
Map<Object, Integer> indexes = new HashMap<>();
for (T obj: objects) {
Object hash = getObjectFieldsHash(obj, fields);
indexes.computeIfAbsent(hash, (_unused) -> indexes.size()); // How can I remove _unused variable?
Integer nextIndex = indexes.get(hash);
if (nextIndex >= result.size()) { // Maybe I could use ==. Does it improve anything?
result.add(new ArrayList<T>()); // Is it possible to create same type of original List instead of always ArrayList?
}
result.get(nextIndex).add(obj);
}
return result;
}
}
Is there any way to improve this?
I'm thinking of:
- I can pass as argument any subtype of
List
, but I'm always returning ArrayLists - I was forced to declare the
_unused
variable in mylambda function
, or won't compile, producing error: "Cannot infer functional interface type" - Does using
==
instead of>=
to check if I already created a sublist provide me any kind of improvement? - I named this method
groupByFields
, but I feel like is the opposite of "flatMap" kind functions. Is there any concept which gives me a more standarized method name?
java performance memory-optimization
New contributor
Mayday is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I have a function that looks up in a list
the elements which share same values in order to group them.
As a fast summary, this should be the input/output:
[A, A', B, C, B', A''] --> [[A, A', A''], [B, B'], [C]]
I do not care about order. It could also produce:
[A, A', B, C, B', A''] --> [[B, B'], [A, A', A''], [C]]
This is my Test Code to see the output samples:
class A {
private Long id;
private String name;
private Object param;
A(Long id, String name, Object param) {
this.id = id;
this.name = name;
this.param = param;
}
@Override
public String toString() {
return "{tid:" + id + ",tname:" + name + ",tparam:" + param + "}";
}
}
public class ListsTest {
private final A a1 = new A(1L, "A", 100);
private final A a2 = new A(2L, "B", 200);
private final A a3 = new A(1L, "A", 300);
private final A a4 = new A(1L, "B", 400);
@Test
public void groupByIdAndName() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupByIdAndName");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "id", "name");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3), List.of(a2), List.of(a4))));
}
@Test
public void groupById() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupById");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "id");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3, a4), List.of(a2))));
}
@Test
public void groupByName() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupByName");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "name");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3), List.of(a2, a4))));
}
}
Which outputs:
groupById
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}], [{ id:1, name:B, param:400}]]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}, { id:1, name:B, param:400}], [{ id:2, name:B, param:200}]]
groupByIdAndName
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}], [{ id:1, name:B, param:400}]]
groupByName
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}, { id:1, name:B, param:400}]]
The code I developed for it is the following:
public class Lists {
private static <T> Object getObjectFieldsHash(T obj, String... fields) throws NoSuchFieldException, IllegalAccessException {
List<Object> vals = new ArrayList<>();
for (String field: fields) {
Field f = obj.getClass().getDeclaredField(field);
f.setAccessible(true);
vals.add(f.get(obj));
}
return Objects.hash(vals);
}
public static <T> List<List<T>> groupByFields(List<T> objects, String... fields ) throws NoSuchFieldException, IllegalAccessException {
List<List<T>> result = new ArrayList<>(); // Is it possible to create same type of original List instead of always ArrayList?
Map<Object, Integer> indexes = new HashMap<>();
for (T obj: objects) {
Object hash = getObjectFieldsHash(obj, fields);
indexes.computeIfAbsent(hash, (_unused) -> indexes.size()); // How can I remove _unused variable?
Integer nextIndex = indexes.get(hash);
if (nextIndex >= result.size()) { // Maybe I could use ==. Does it improve anything?
result.add(new ArrayList<T>()); // Is it possible to create same type of original List instead of always ArrayList?
}
result.get(nextIndex).add(obj);
}
return result;
}
}
Is there any way to improve this?
I'm thinking of:
- I can pass as argument any subtype of
List
, but I'm always returning ArrayLists - I was forced to declare the
_unused
variable in mylambda function
, or won't compile, producing error: "Cannot infer functional interface type" - Does using
==
instead of>=
to check if I already created a sublist provide me any kind of improvement? - I named this method
groupByFields
, but I feel like is the opposite of "flatMap" kind functions. Is there any concept which gives me a more standarized method name?
java performance memory-optimization
New contributor
Mayday is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I have a function that looks up in a list
the elements which share same values in order to group them.
As a fast summary, this should be the input/output:
[A, A', B, C, B', A''] --> [[A, A', A''], [B, B'], [C]]
I do not care about order. It could also produce:
[A, A', B, C, B', A''] --> [[B, B'], [A, A', A''], [C]]
This is my Test Code to see the output samples:
class A {
private Long id;
private String name;
private Object param;
A(Long id, String name, Object param) {
this.id = id;
this.name = name;
this.param = param;
}
@Override
public String toString() {
return "{tid:" + id + ",tname:" + name + ",tparam:" + param + "}";
}
}
public class ListsTest {
private final A a1 = new A(1L, "A", 100);
private final A a2 = new A(2L, "B", 200);
private final A a3 = new A(1L, "A", 300);
private final A a4 = new A(1L, "B", 400);
@Test
public void groupByIdAndName() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupByIdAndName");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "id", "name");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3), List.of(a2), List.of(a4))));
}
@Test
public void groupById() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupById");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "id");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3, a4), List.of(a2))));
}
@Test
public void groupByName() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupByName");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "name");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3), List.of(a2, a4))));
}
}
Which outputs:
groupById
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}], [{ id:1, name:B, param:400}]]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}, { id:1, name:B, param:400}], [{ id:2, name:B, param:200}]]
groupByIdAndName
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}], [{ id:1, name:B, param:400}]]
groupByName
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}, { id:1, name:B, param:400}]]
The code I developed for it is the following:
public class Lists {
private static <T> Object getObjectFieldsHash(T obj, String... fields) throws NoSuchFieldException, IllegalAccessException {
List<Object> vals = new ArrayList<>();
for (String field: fields) {
Field f = obj.getClass().getDeclaredField(field);
f.setAccessible(true);
vals.add(f.get(obj));
}
return Objects.hash(vals);
}
public static <T> List<List<T>> groupByFields(List<T> objects, String... fields ) throws NoSuchFieldException, IllegalAccessException {
List<List<T>> result = new ArrayList<>(); // Is it possible to create same type of original List instead of always ArrayList?
Map<Object, Integer> indexes = new HashMap<>();
for (T obj: objects) {
Object hash = getObjectFieldsHash(obj, fields);
indexes.computeIfAbsent(hash, (_unused) -> indexes.size()); // How can I remove _unused variable?
Integer nextIndex = indexes.get(hash);
if (nextIndex >= result.size()) { // Maybe I could use ==. Does it improve anything?
result.add(new ArrayList<T>()); // Is it possible to create same type of original List instead of always ArrayList?
}
result.get(nextIndex).add(obj);
}
return result;
}
}
Is there any way to improve this?
I'm thinking of:
- I can pass as argument any subtype of
List
, but I'm always returning ArrayLists - I was forced to declare the
_unused
variable in mylambda function
, or won't compile, producing error: "Cannot infer functional interface type" - Does using
==
instead of>=
to check if I already created a sublist provide me any kind of improvement? - I named this method
groupByFields
, but I feel like is the opposite of "flatMap" kind functions. Is there any concept which gives me a more standarized method name?
java performance memory-optimization
New contributor
Mayday is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have a function that looks up in a list
the elements which share same values in order to group them.
As a fast summary, this should be the input/output:
[A, A', B, C, B', A''] --> [[A, A', A''], [B, B'], [C]]
I do not care about order. It could also produce:
[A, A', B, C, B', A''] --> [[B, B'], [A, A', A''], [C]]
This is my Test Code to see the output samples:
class A {
private Long id;
private String name;
private Object param;
A(Long id, String name, Object param) {
this.id = id;
this.name = name;
this.param = param;
}
@Override
public String toString() {
return "{tid:" + id + ",tname:" + name + ",tparam:" + param + "}";
}
}
public class ListsTest {
private final A a1 = new A(1L, "A", 100);
private final A a2 = new A(2L, "B", 200);
private final A a3 = new A(1L, "A", 300);
private final A a4 = new A(1L, "B", 400);
@Test
public void groupByIdAndName() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupByIdAndName");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "id", "name");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3), List.of(a2), List.of(a4))));
}
@Test
public void groupById() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupById");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "id");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3, a4), List.of(a2))));
}
@Test
public void groupByName() throws IllegalAccessException, NoSuchFieldException {
List<A> aList = List.of(a1, a2, a3, a4);
System.out.println("groupByName");
System.out.println("Input: ---> " + aList);
List<List<A>> aGroupedBy = Lists.groupByFields(aList, "name");
System.out.println("Output: --> " + aGroupedBy);
System.out.println("------------------------------------------------------------------------");
assertThat(aGroupedBy, is(List.of(List.of(a1, a3), List.of(a2, a4))));
}
}
Which outputs:
groupById
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}], [{ id:1, name:B, param:400}]]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}, { id:1, name:B, param:400}], [{ id:2, name:B, param:200}]]
groupByIdAndName
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}], [{ id:1, name:B, param:400}]]
groupByName
Input: ---> [{ id:1, name:A, param:100}, { id:2, name:B, param:200}, { id:1, name:A, param:300}, { id:1, name:B, param:400}]
Output: --> [[{ id:1, name:A, param:100}, { id:1, name:A, param:300}], [{ id:2, name:B, param:200}, { id:1, name:B, param:400}]]
The code I developed for it is the following:
public class Lists {
private static <T> Object getObjectFieldsHash(T obj, String... fields) throws NoSuchFieldException, IllegalAccessException {
List<Object> vals = new ArrayList<>();
for (String field: fields) {
Field f = obj.getClass().getDeclaredField(field);
f.setAccessible(true);
vals.add(f.get(obj));
}
return Objects.hash(vals);
}
public static <T> List<List<T>> groupByFields(List<T> objects, String... fields ) throws NoSuchFieldException, IllegalAccessException {
List<List<T>> result = new ArrayList<>(); // Is it possible to create same type of original List instead of always ArrayList?
Map<Object, Integer> indexes = new HashMap<>();
for (T obj: objects) {
Object hash = getObjectFieldsHash(obj, fields);
indexes.computeIfAbsent(hash, (_unused) -> indexes.size()); // How can I remove _unused variable?
Integer nextIndex = indexes.get(hash);
if (nextIndex >= result.size()) { // Maybe I could use ==. Does it improve anything?
result.add(new ArrayList<T>()); // Is it possible to create same type of original List instead of always ArrayList?
}
result.get(nextIndex).add(obj);
}
return result;
}
}
Is there any way to improve this?
I'm thinking of:
- I can pass as argument any subtype of
List
, but I'm always returning ArrayLists - I was forced to declare the
_unused
variable in mylambda function
, or won't compile, producing error: "Cannot infer functional interface type" - Does using
==
instead of>=
to check if I already created a sublist provide me any kind of improvement? - I named this method
groupByFields
, but I feel like is the opposite of "flatMap" kind functions. Is there any concept which gives me a more standarized method name?
java performance memory-optimization
java performance memory-optimization
New contributor
Mayday is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Mayday is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 17 hours ago
Mayday
New contributor
Mayday is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 17 hours ago
MaydayMayday
1063
1063
New contributor
Mayday is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Mayday is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Mayday is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Mayday is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211257%2fgrouping-items-in-a-list-into-inner-lists-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Mayday is a new contributor. Be nice, and check out our Code of Conduct.
Mayday is a new contributor. Be nice, and check out our Code of Conduct.
Mayday is a new contributor. Be nice, and check out our Code of Conduct.
Mayday is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211257%2fgrouping-items-in-a-list-into-inner-lists-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
dfc,D nZiqPxm8Lldouk7YrQ6yVql5 yNUrIuWkqZphXHTB7h UFoQP8 ip71YO0 PSIygHVqpl