在将下一个子元素推送到新行之前,CSS中的一种简单方法是在同一行上具有固定的最大子项吗?

据我了解flexbox,如果子项目在其上方的线上有足够的可用空间,则只会将其推送到新行.但是我正在寻找一个CSS规则或函数,让我说" 我想在任何给定的行上最多有3个子项,即使空间可用于第4个,也可以将它推到新行 ".
我有一个递归方法,我想在特定的 if 语句返回 true 时返回一个值(它总是这样做)
if (compactArray != null) {
if (arrayCount == (compactArray[0].length - 1)) {
return compactArray;//i want to return here
}
}
Run Code Online (Sandbox Code Playgroud)
但 Java 不会让我从 if 返回,并抛出警告,提示我需要添加返回值。
一个人做什么?完整方法如下
public String[][] diXmlRecursiveRead(Iterator<Element> list, String[] columnNames, String[][] compactArray,
Integer arrayCount) {
Element element = null;
String[] columns = null;
while (list.hasNext()) {
element = list.next();
// Assign data to the two dimensional array, starting from position
// 1 in the length to not overwrite the column names.
// This …Run Code Online (Sandbox Code Playgroud)