January 27, 2020

Finding the Current Flush Mode for the JPA EntityManager

Knowing the current flush mode can be done as follows: // via EntityManagerentityManager.getFlushMode();// in Hibernate JPA, via Session(entityManager.unwrap(Session.class)).getFlushMode();// starting with Hibernate 5.2(entityManager.unwrap(Session.class)).getHibernateFlushMode();

Find if a string contains one of the given words in Java

We can use the AnyMatch method to figure out if a string contains any of the given words from an Array. See below for a sample.  List middleEasternCountries = Arrays.asList(“egypt”, “iran”, “turkey”);String sampleString = “Egypt is a famous tourist destination. It contains the Pyramids”; System.out.println(middleEasternCountries.stream().anyMatch(sampleString::contains));

Transpose a Matrix in Python

One of the inbuilt libraries in Python is zip. It can be utilized to transpose a matrix by performing an Unzip followed by zip. Sample code below.   Python comes with many inbuilt libraries zip is among those. The??zip()??function returns an iterator of tuples based on the??iterable??object. In order to get the transpose of the matrix first, we need to unzip the list using??*??operator then zip it. inputMatrix = [ [7, 14, 21], [1, 2, 3] ]zip(*inputMatrix) Output will be as follows:[ (7, 1), (14, 2), (21, 3) ]