-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8, 11, 17, 22, 23
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
Windows 11, Java 17
A DESCRIPTION OF THE PROBLEM :
please run this and check the output
public static List<List<Integer>> printAllCombination2(int[] arr) { //1,2,3,4
if(arr == null || arr.length<1)
return new ArrayList<>();
List<List<Integer>> intlist = new ArrayList<>();
for(int i=0; i<arr.length; i++) {
int j=i;
List<Integer> ilist = new ArrayList<>();
while(j<arr.length) {
ilist.add(arr[j]);
intlist.add(ilist);
j++;
}
}
return intlist;
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the code which has provided in the description, list object is behaving differently
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
[[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2], [2, 3], [2, 3, 4], [3], [3, 4], [4]]
ACTUAL -
[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [2, 3, 4], [2, 3, 4], [2, 3, 4], [3, 4], [3, 4], [4]]
---------- BEGIN SOURCE ----------
import java.util.ArrayList;
import java.util.List;
public class TestProgram {
public static List<List<Integer>> printAllCombination2(int[] arr) { //1,2,3,4
if(arr == null || arr.length<1)
return new ArrayList<>();
List<List<Integer>> intlist = new ArrayList<>();
for(int i=0; i<arr.length; i++) {
int j=i;
List<Integer> ilist = new ArrayList<>();
while(j<arr.length) {
ilist.add(arr[j]);
intlist.add(ilist);
j++;
}
}
return intlist;
}
public static void main(String[] args) {
int[] arr = {1,2,3,4};
System.out.println(" combinations :::: "+printAllCombination2(arr));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
import java.util.ArrayList;
import java.util.List;
public class TestProgram {
public static List<List<Integer>> printAllCombination1(int[] arr) {
if(arr == null || arr.length<1)
return new ArrayList<>();
List<List<Integer>> intlist = new ArrayList<>();
for(int i=0; i<arr.length; i++) { //1,2,3,4
int j=i;
List<Integer> ilist = new ArrayList<>();
while(j<arr.length) {
ilist.add(arr[j]);
List<Integer> nlist = new ArrayList<>(ilist);
intlist.add(nlist);
j++;
}
}
return intlist;
}
public static void main(String[] args) {
int[] arr = {1,2,3,4};
System.out.println(" combinations :::: "+printAllCombination1(arr));
}
}
FREQUENCY : always
Windows 11, Java 17
A DESCRIPTION OF THE PROBLEM :
please run this and check the output
public static List<List<Integer>> printAllCombination2(int[] arr) { //1,2,3,4
if(arr == null || arr.length<1)
return new ArrayList<>();
List<List<Integer>> intlist = new ArrayList<>();
for(int i=0; i<arr.length; i++) {
int j=i;
List<Integer> ilist = new ArrayList<>();
while(j<arr.length) {
ilist.add(arr[j]);
intlist.add(ilist);
j++;
}
}
return intlist;
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the code which has provided in the description, list object is behaving differently
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
[[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2], [2, 3], [2, 3, 4], [3], [3, 4], [4]]
ACTUAL -
[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [2, 3, 4], [2, 3, 4], [2, 3, 4], [3, 4], [3, 4], [4]]
---------- BEGIN SOURCE ----------
import java.util.ArrayList;
import java.util.List;
public class TestProgram {
public static List<List<Integer>> printAllCombination2(int[] arr) { //1,2,3,4
if(arr == null || arr.length<1)
return new ArrayList<>();
List<List<Integer>> intlist = new ArrayList<>();
for(int i=0; i<arr.length; i++) {
int j=i;
List<Integer> ilist = new ArrayList<>();
while(j<arr.length) {
ilist.add(arr[j]);
intlist.add(ilist);
j++;
}
}
return intlist;
}
public static void main(String[] args) {
int[] arr = {1,2,3,4};
System.out.println(" combinations :::: "+printAllCombination2(arr));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
import java.util.ArrayList;
import java.util.List;
public class TestProgram {
public static List<List<Integer>> printAllCombination1(int[] arr) {
if(arr == null || arr.length<1)
return new ArrayList<>();
List<List<Integer>> intlist = new ArrayList<>();
for(int i=0; i<arr.length; i++) { //1,2,3,4
int j=i;
List<Integer> ilist = new ArrayList<>();
while(j<arr.length) {
ilist.add(arr[j]);
List<Integer> nlist = new ArrayList<>(ilist);
intlist.add(nlist);
j++;
}
}
return intlist;
}
public static void main(String[] args) {
int[] arr = {1,2,3,4};
System.out.println(" combinations :::: "+printAllCombination1(arr));
}
}
FREQUENCY : always