[Solved] Stream filter regex [closed]

You can use String’s startsWith method for this: List<File> fileListToProcess = Arrays.stream(allFolderPath) .filter(myFile -> myFile.getName().startsWith(“archive_”)) .collect(Collectors.toList()); OR You can use following regex to check if your string starts with archive_: ^(archive_).* like: List<File> fileListToProcess = Arrays.stream(allFolderPath) .filter(myFile -> myFile.getName().matches(“^(archive_).*”)) .collect(Collectors.toList()); solved Stream filter regex [closed]

[Solved] When post request is done in postman it passes all the values as NULL

It looks like the JSON that you’re sending as your POST payload is not a representation of a Student object. Instead, it’s a representation of an object that contains two members, a Student object named student, and a String named id. { “student”:{ //<– This is a Student object “firstname”: “jay”, “lastname”: “patel”, “studentId”: “2”, … Read more

[Solved] Why do I Have to append the method signature with throws Exception when try block is being used?

The right way to do this, btw, is to just allow ArithmeticException to end the program if needed. public class Exam { private static void div(int i, int j) throws ArithmeticException { System.out.println(i / j); } public static void main(String[] args) throws Exception { div(5, 0); } } Much cleaner and clearer, and the exception … Read more

[Solved] How to refacor a code use only loops and simple arrays?

public class Anagram { public static void main(String[] args) { String text = “!Hello123 “; char[] chars = text.toCharArray(); int left = 0; int right = text.length() – 1; while (left < right) { boolean isLeftLetter = Character.isLetter(chars[left]); boolean isRightLetter = Character.isLetter(chars[right]); if (isLeftLetter && isRightLetter) { swap(chars, left, right); left++; right–; } else { … Read more

[Solved] Hi, the requirement is to display the user input in table format

1.Read about difference between “==” OR “equals”,sysout.printf and clean code. public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Port obj = new Port(); int count, i; String b ; System.out.println(“Enter the number of students”); count= sc.nextInt(); int[] age = new int[count]; String[] name = new String[count]; String[] country=new String[count]; for (i = … Read more

[Solved] New to coding and getters and setters are not working to a new class? [closed]

First of all, I might think you have copied the program from an external source, since there is lots of compilation errors. Anyways… try this this might work… import java.util.Scanner; public class DemoPayroll { public static void main(String[] args) { Payroll newEmpInfoObject = new Payroll(); System.out.println(“Enter name”); Scanner keyboard = new Scanner(System.in); String name = … Read more

[Solved] How to skip/not run a code in java

Place the other code in an else: public void actionPerformed(ActionEvent e){ if(t1.getText().equals(“Name”) || t2.getText().equals(“Section”) || t3.getText().equals(“Age”)){ JOptionPane.showMessageDialog(null, “Please fill in the incomplete fields”); } else { //If the ‘if statement’ above is true, these code below will not execute t8.setText(t1.getText() + ” of ” + t2.getText() + ” — ” + t3.getText() + ” years … Read more

[Solved] Why not everything is static function in java? Any differences in following two examples? [duplicate]

Your question simplifies to “Why do Object Oriented Programming when you can write Procedural?” OOP vs Functional Programming vs Procedural Besides that, you now need somewhere to store your Cuboid data. Might as well create a Cuboid object anyway, right? 1 solved Why not everything is static function in java? Any differences in following two … Read more

[Solved] Java 8 – collecting into a map from a list of objects with nested list

Assuming you want a Map<User.userId, List<UserData.customerId>> you can use this: Map<Long, List<Long>> result = users.stream() .collect(Collectors.toMap( User::getUserId, u -> u.getUserData().stream() .map(UserData::getCustomerId) .collect(Collectors.toList()) )); 3 solved Java 8 – collecting into a map from a list of objects with nested list

[Solved] What if the meaning of that expression if(x > y / z)

It’s x > (y / z). The expression y / z returns a number which is being compared to x. The operator precedence table explains why it works even without round brackets. ┌────────────────┬───────────────────────────────┐ │ Operators │ Precedence ↓ │ ├────────────────┼───────────────────────────────┤ │ multiplicative │ * / % │ │ relational │ < > <= >= instanceof … Read more