All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.jalokim.propertiestojson.util.ListUtil Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
package pl.jalokim.propertiestojson.util;

import java.util.Collection;
import java.util.List;

import static java.lang.String.format;

public class ListUtil {
    public static boolean isLastIndex(List list, int index) {
        return getLastIndex(list) == index;
    }

    public static int getLastIndex(Collection list) {
        return list.size() - 1;
    }

    public static int getLastIndex(Object[] array) {
        return array.length - 1;
    }

    public static String everyElementAsNewLine(Collection collection) {
        StringBuilder stringBuilder = new StringBuilder();
        for(Object element : collection) {
            stringBuilder.append(element.toString());
            stringBuilder.append(format("%n"));
        }
        return stringBuilder.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy