Skip to content

Tag: java

How to make a regular expression for this seemingly simple case?

Is it possible to write a regular expression that works with String replaceAll() to remove zero or more spaces from the end of a line and replace them with a single period (.). For example, a regex that will make these (non-exhaustive) test cases pass: I know I can do it with replaceFirst(” *$”, &…

transform java.sql.Date to LocalDateTime

I have a java.sql.Date object and want to transform it to a java.time.LocalDateTime object. For comparison, I am able to do a similar transformation using java.util.Date: This answer doesn’t work for me, as my java.sql.Date does not have a getTimestamp method. For reference, this question addresses the …

Apache Beam Resampling of columns based on date

I am using ApacheBeam to process data and trying to achieve the following. read the data from CSV file. (Completed ) Group the records based on Customer ID (Completed) Resample the data based on month and calculate the sum for that particular month. Detailed Explanation: I have a CSV file as shown below. cust…

Prime numbers – I need clarification on code implementation

This is the code I know: But is this ok if you’re looking for prime numbers: Output: And also is there much difference in time complexity? Answer Your code is incorrect. This code only works because you are taking the value of n as 30, for a greater number like 1000 this will produce an incorrect result. List…

XSLT filitering for both begin with and followed by characters

I am working in project where I am given a list of allowed characters, and required to remove the unwanted characters. I have the following done, but I felt it is cumbersome and than it should be Testing the start condition I have added three checks. The contains check returns true for empty string case, and …

Can I use a lambda function like this?

I want to try to use lambda functions (which I do not understand well) so I can learn more about them. I have an assignment on trees that has us making a family tree class. children is a set of all of the children nodes to this node. Also as a side question, does this usage of AtomicInteger work similarly