
Posted In: Java Core, String
How to replace string inside curly brackets
Three possible ways 1. Use replace function. In this case do not escape curly brackets 2. Use replaceAll function. In this case escape curly brackets because replaceAll uses regular expression 3. Use java.text.MessageFormat class if string to replace is like {0}, {1}, {2} This code snippets were useful while testing Spring Rest URLs with a […]
Read More
Posted In: Java Core, String
How to parse a mathematical expression given as a string – using ScriptEngine
Evaluating a math expression given in string form package com.example.mathexpression; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import org.junit.Test; public class MathExpression2 { @Test public void evaluate1() throws Exception { System.out.println(“\nevaluate1() start”); ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine engine = mgr.getEngineByName(“JavaScript”); String result = “5+4*(7-15)”; System.out.println(engine.eval(result)); } }
Read MoreTags: String mathematical expression

Posted In: Java Core, String
How to parse a mathematical expression given as a string – using Bean Shell
Evaluating a math expression given in string form Maven beanshell beanshell import package com.example.mathexpression; import org.junit.Test; import bsh.Interpreter; public class MathExpression { @Test public void evaluate1() throws Exception { System.out.println(“\nevaluate1() start”); Interpreter interpreter = new Interpreter(); interpreter.eval(“result = 5+4*(7-15)”); System.out.println(interpreter.get(“result”)); } }
Read MoreTags: String mathematical expression

Posted In: Java Core, String
How to read and parse CSV file using Guava Splitter
Splitting a comma-separated string but ignoring commas in quotes Maven guava Guava Splitter Works only without commas in quotes data Works with commas in quotes data
Read MoreTags: CSV

Posted In: Java Core, String
How to read and parse CSV file using String Pattern
Splitting a comma-separated string but ignoring commas in quotes Parsing CSV input with a RegEx in java
Read MoreTags: CSV

Posted In: Java Core, String
How to read and parse CSV file using Open CSV
Splitting a comma-separated string but ignoring commas in quotes Maven opencsv Example csv (cm24AUG2017bhav.csv) Example csv commas in quotes (cm24AUG2017bhav1.csv) opencsv import With deprecated CSVReader. Use CSVReaderBuilder With deprecated CSVReader. Use CSVReaderBuilder. commas in quotes data With CSVReaderBuilder With CSVReaderBuilder. commas in quotes data With CsvToBean and ColumnPositionMappingStrategy. CsvToBean.parse is deprecated With header element name
Read MoreTags: CSV

Posted In: Java Core, String
How to read and parse CSV file using Apache Commons CSV
Splitting a comma-separated string but ignoring commas in quotes Maven commons-csv Example csv Example csv commons csv import With element index With header element name With header name and with commas in quotes With header name RFC4180 format
Read MoreTags: CSV

Posted In: Java Core, String
String vs StringBuilder vs StringBuffer Simple Benchmark test
Since String is immutable in java any changes to it creates a new object. StringBuffer and StringBuilder are mutable objects. They provide methods like append(), insert(), delete() and substring() to manipulate date. This test clearly shows that always use StringBuilder. It will perform much better than String concatenation. Result
Read More
Posted In: Java Core, String
When to use StringBuilder vs String concatenation
Most of the discussions say that for few fields String concatenation is fine. If code is looping then do use StringBuilder. Use StringBuilder for following kind of code There is slight different issue with this may be approach. Applications which go through various static code analysis tools should always use StringBuilder append than String concatenation. […]
Read More
Posted In: Java Core, String
How to convert a String to an int in Java
Techniques used 1. Using Integer Class 2. Using BigInteger Class 3. Apache Commons IOUtils 4. Guava library
Read More- Apache (13)
- Build Tools (2)
- Gradle (2)
- Caching (1)
- cpanel (1)
- cURL (1)
- Database (7)
- Hibernate (5)
- Java Core (38)
- Java Script (15)
- Bootstrap (1)
- File Upload (7)
- jQuery (3)
- React (3)
- JEE (13)
- JSON (41)
- GSON (13)
- Jackson 1X (1)
- Jackson 2X (12)
- jsoniter (1)
- Logging (2)
- Apache Commons Logging (1)
- Apache Log4J (1)
- Logback (1)
- SLF4J (1)
- MongoDB (1)
- OS (1)
- Linux (1)
- Security (5)
- Server (4)
- Tomcat (4)
- Service (2)
- Micro (2)
- Spring (46)
- Pattern (2)
- Spring Boot (20)
- Spring Data (4)
- Spring MVC (8)
- Spring REST (13)
- Spring Security (7)
- Testing (11)
- XML (5)
- JDOM XML Parser (1)