hi everyone , i have list of student which contains null value in some fields and i want remove the null value and set N/A in that place , i am beginner in java so please help me out. code are given below:-
public class MainMathod { //list of data filter using stream api in java public static void useStream(List<Student> students) { students.stream() .map(x -> (x == null) ? "N/A" : x) .collect(Collectors.toList()); } public static void main(String[] args) { List<Student> students = Arrays.asList(new Student(1, "rohit", "lama", "5", "chanfdarjoti"), new Student(1, "rohit", "lama", "5", "chanfdarjoti"), new Student(2, "rohit", "lama", "5", "chanfdarjoti"), new Student(3, "rohit", "lama", "9", "chanfdarjoti"), new Student(4, "raju", null, "5", "chanfdarjoti"), new Student(5, "himal", null, "4", "chanfdarjoti"), new Student(56, "null", "mudbhari", "5", "chanfdarjoti"), new Student(16, "rai", "lama", "3", "chanfdarjoti"), new Student(18, "null", "baskota", "7", "chanfdarjoti"), new Student(199, "rajes", "lama", "5", "chanfdarjoti"), new Student(188, "sabina", "khatri", "10", "chanfdarjoti"), new Student(1899, "bina", "lama", "5", "chanfdarjoti"), new Student(1, "pradesh", "lama", "11", "chanfdarjoti"), new Student(1, "teus", "lama", "5", "chanfdarjoti") ); students.removeAll(Collections.singletonList(null)); } } https://stackoverflow.com/questions/66593243/how-to-replace-null-value-inside-java-list-with-costume-text March 12, 2021 at 10:13AM
没有评论:
发表评论