How do I check if a string contains a substring in java

String string = "Madam, I am Achyu";

// Starts with
boolean  b = string.startsWith("Mad");  // true

// Ends with
b = string.endsWith("dam");             // true

// Anywhere
b = string.indexOf("I am") >= 0;        // true

// To ignore case, regular expressions must be used

// Starts with
b = string.matches("(?i)mad.*");

// Ends with
b = string.matches("(?i).*achyu");

// Anywhere
b = string.matches("(?i).*i am.*");
Advertisements

Many to many relationship with bi-directional save and update.

user profile :

@ManyToMany
@JoinTable(name = “user_has_role”, joinColumns = {@JoinColumn(name = “user_id”) }, inverseJoinColumns = { @JoinColumn(name = “role_id”) },
uniqueConstraints = {@UniqueConstraint(
columnNames = {“user_id”, “role_id”}, name = “UK_USER_ROLE”)})
List<Role> roleList;

role :

@ManyToMany
@JoinTable(name = “user_has_role”, joinColumns = {@JoinColumn(name = “role_id”) }, inverseJoinColumns = { @JoinColumn(name = “user_id”) })
List<UserProfile> userList;

ManyToMany relationship using JPA with Hibernate provide unique key constraint

Here’s a way to solve the problem:

UserProfile.java:

@ManyToMany
@JoinTable(name = “user_has_role”, joinColumns = {@JoinColumn(name = “user_id”) }, inverseJoinColumns = { @JoinColumn(name = “role_id”) },
uniqueConstraints = {@UniqueConstraint(
columnNames = {“user_id”, “role_id”}, name = “UK_USER_ROLE”)})
List<Role> roleList;

This is for unidirectional mapping. If you want a bidirectional relationship, change the mapping in

Role.class to the same.

How To use give dynamic message to ngdilog template

var newScope = $scope.$new();
newScope.statusOperation = $scope.user.status==’Active’?’deactivate’:’activate’;
ngDialog
.openConfirm(
{

template : ‘<p>Are you sure you want to {{statusOperation}} selected user?</p>’
+ ‘

‘,

plain : true,
scope: newScope,
className : ‘ngdialog-theme-default’
})
.then(function (value) {
}