[Solved] regex to find variables surrounded by % in a string

I believe you are looking for a regex pattern (?<!%%)(?<=%)\w+(?=%)(?!%%) That would find variables that are surrounded by a single % character on each side. Test the regex here. Java code: final Pattern pattern = Pattern.compile(“(?<!%%)(?<=%)\\w+(?=%)(?!%%)”); final Matcher matcher = pattern.matcher(input); while (matcher.find()) { System.out.println(matcher.group(0)); } Test the Java code here. UPDATE: If you want … Read more

[Solved] Why the mapping.xml and configuration.xml has to be outside the pojo package?

I have just started to learn the Hibernate and found this in various online sites : mapping.xml and config.xml has to be defined outside the pojo package? You can put xml configurations whenever you want. For an example SessionFactory factory = new Configuration().configure().buildsessionFactory(); Configure a session factory from the default hibernate.cfg.xml. It is the same … Read more

[Solved] The requirement is, the output will print one number followed by a character then a number and so on

well thanks for not helping me out i helped my self import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Scanner; public class Test4 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner gaba = new Scanner( System.in ); String variable; System.out.print(“Enter String:”); variable = gaba.nextLine(); SeparateGaba(variable); } public static void … Read more

[Solved] Java String.split() without specific symbol [closed]

You can do that with split() and some regex-magic: System.out.println( Arrays.toString( “3332255766122”.split( “(?<=(.))(?!\\1)” ) )); Output: [333, 22, 55, 7, 66, 1, 22] Regex breakdown: (?<=x) is a positive zero-width look-behind, so it will match the position right after the match for subexpression x (.) as epxression for x above is a capturing group that … Read more

[Solved] Why an object is removed after using removeAll method

Because you called a1.removeAll(a2) perhaps? http://docs.oracle.com/javase/7/docs/api/java/util/List.html#removeAll%28java.util.Collection%29 Removes from this list all of its elements that are contained in the specified collection (optional operation). So, in other words, every element that’s in a2 and also in a1 will be removed from a1. 2 solved Why an object is removed after using removeAll method

[Solved] Printing characters from a string occurring in another string [closed]

You can use the code similar to this which gives the required output public class ProgramOnStrings { public static void main(String[] args) { // TODO Auto-generated method stub Compare cobj=new Compare(); cobj.compareStrings(); } } class Compare { String s1=”helloworld”; String s2=”hord”; int array[]; String small,big; Compare() { if(s1.length()<s2.length()) { small=s1; big=s2; array=new int[small.length()]; } else … Read more

[Solved] Calling the methods in java

Your Draw class extends the android class View. You are adding a view to your layout in the onCreateMethod(): linearLayout.addView(draw); Android will call the onDraw() method in the draw object when the view is rendering. 2 solved Calling the methods in java

[Solved] Fetching last 200 records from table [closed]

include the order by clause to get the last 200 records. SELECT c.member_id,c.message_id, fm.firstname AS fname, up.gender, TIMESTAMPDIFF( YEAR, up.dob, NOW( ) ) AS age, c.upload_img, c.image, c.message_id AS msg_id, c.message AS msg, c.posted_timestamp AS time, c.topic_id AS topic_id, u.croppedpicture_filename,u.picture_filename FROM conversation_messages_tbl c, user_profileinformation_tbl up, user_tbl u, family_member_tbl fm WHERE c.member_id = fm.family_member_id AND up.user_id … Read more

[Solved] Arithmetic expression before the equal sign

Your so called equal sign (=) is actually assignment operator in programming world. Equal sign is double equal == which may use in logical opeartion. ctr =+ 1; // means, assign positive 1 into ctr, Compile fine ctr =- 1; // means, assign negative 1 into ctr, Compile fine ctr =* 1; //Compilation error like … Read more

[Solved] Java reserved words as identifiers [closed]

I think you may have figured out by yourself that reserve words are also case sensitive when you say that Java is case sensitive. Using LONG as identifier would not cause any problem for the Java compiler, but the problem is variable name LONG may not mean much and might not contribute to a readable … Read more

[Solved] null pointer exception in java servlet [closed]

I got a “null pointer exception” fault in java servlet. Could someone tell me what happens? And how to avoid that? That happens when you’re trying to access/invoke some reference which is actually null. SomeObject someObject = null; someObject.doSomething(); // Throws NullPointerException. You need to make sure that you only access/invoke it when it is … Read more