How To Split Java String By NewlinesJuly 19th, 2007 Splitting a String by newline is a common requirement. When processing textual data from files or from web we need to split the data by newline boundaries.
Java Program: Compare two text filesApril 29th, 2009 Today while managing the comments, I got a request of this sort. HI,
I have a small question in java.
HSQLDB Tip: Case Insensitive LIKE Query in HSQLDB RDBMS & Space Crunched String ComparisonJuly 21st, 2007 I previously discussed how to extend HSQLDB relational database with simple Java functions. The example there actually implements case insensitive like query functionality for HSQLDB.
Keyboard Shortcuts to Merge, Change and Save Large MS Word Documents March 17th, 2009 My friend was merging some changes in a large Microsoft word document the other day. He opened the the BASE MS Word document (the document where the changes were originally made from) and then used the Compare and Merge Documents… functionality (located under the Tools Menu) to compare it to the document that had the new changes.
How To trim() in JavascriptMarch 17th, 2006 Javascript doesn't natively support trim on strings. It is however very easy to implement with regular expressions.
Java Software Programming Examples For Beginners / Interview: How To Swap Integer (and String) Variables Without Using a Temporary VariableOctober 29th, 2005 A Simple Programming Question for Beginners
Writing Comparator for sorting on columnsJanuary 25th, 2004 The challenge is to write a generic comparator which allows for sorting of the data based on a chosen column in either ascending or descending order when the column data type is not known upfront. When I faced with providing the ability to sort based on columns, I realized I had to implement a comparator which based on sorting criteria can sort in either ascending or descending order.
Java Software: 1-Line Sort & Uniq UtilityOctober 18th, 2005 I had to sort and uniq (create a unique set of strings) a large list with lots of duplicate. My options were to write it in Java or download cygwin and run: cat file | sort | uniq > result
Cygwin download never works for me.
Comprehensive AWK Manual & AWK ExampleSeptember 2nd, 2007 I extensively use awk (along with cut and grep) for data processing of log files or for any text processing needs. AWK is an excellent text processing tool / filter and report generator.
Cheapest Shortcut To Increase Blog ReadershipAugust 30th, 2007 For 75$ a blogspot blogger hopes to increase his blog readership. Guess where he is looking for help.
Tips on Java Software Certification OptionsNovember 28th, 2005 I have received several questions regarding java certifications. This is a concise guide to java software certification options for java developers, software architects, non-developers like project managers, product managers etc.
Google Ahead of Microsoft in Popularity; Java Way Ahead of Paris HiltonJuly 7th, 2006 Google has passed Microsoft in popularity since beginning of 2005. What is even more surprising is their rate of growth and slow decline of Microsoft.
Discussion & Examples: Java enums versus public static finalSeptember 23rd, 2008 Should we use to represent a constant String such as browser's user agent or simply use public static final String as before?
Using public static final as enum has many problems, such as:
Not typesafe - Since a type is just an int you can pass in any other int value where a particular type is required, or add two types together (which makes no sense). This is particularly noticeable in C programs where you will find strange constants being used in un-related place and yet it seems to work, simply because the required constant and the provided constant share the same int value.
How to hack Google Chrome and Run in Windows 7January 15th, 2009 Trust Windows to come up with problems before they can give you a solution to a previous. The other day, I heard that there is a problem for the new Windows 7 beta users.
How To Compare Product IdeasSeptember 17th, 2007 I am faced with the task to evaluate between several strongly competing product ideas in Web 2.0 space. It is not an easy task to evaluate strong competing ideas, each with a reasonable business model, in this space because of unpredictability of the market.
February 26th, 2006 at 3:52 am
This is highly problematic. intern() will pollute the intern constant pool and you will not get the entries out of the pool. I think it is the best to use a private data structure mimicking the behaviour.
February 26th, 2006 at 8:13 am
Hi,
I’m not sure whether using intern should really be recommended.
Actually if you compare the speed of intern versus a simple hashmap at least on SUN JDK 1.4 the hashmap is much faster. Another point is the String.equals first compares for == anyway. So there’s almost no point to use == directly.
You are right some XML parsers use intern, but I’m not sure that is optimal. They may save some memory by using intern instead of a simple HashMap.
Regards,
Markus
February 26th, 2006 at 9:00 am
Thanks for the correction. I checked with sample code and you guys are absolutely right. With current versions of JDK (I tested with 1.5) I couldn’t find any performance difference.
However I couldn’t understand the “intern() will pollute the intern constant pool and you will not get the entries out of the pool” part.
Do you mean not being able to garbage collect?
Christian, can you please clarify?
February 27th, 2006 at 2:29 am
Older JVMs will put .intern()’ed strings into a pool of strings that live for the duration of the JVM instance. Thus, if a long-living process uses .intern() on dynamic strings, it will eventually run out of memory.
A quick test is this program:
public static void main(String[] args) {
while (true) {
System.out.println(String.valueOf(Math.random()).intern());
}
}
- it may run out of memory.
March 1st, 2006 at 2:14 am
Hi,
Regarding your last comment, it was my understanding that since 1.5 there are no performance advantages to doing:
StringBuffer buff = New StringBuffer("first bit");
buff.append(" next bit");
instead of:
String myString = "first bit"+"next bit";
as most 1.5 jvm implement the string + operator using the StringBuffer class anyway.
Please correct me if I am wrong.
March 23rd, 2006 at 11:35 am
In your specific case,
String myString = "first bit"+"next bit";is still better, since the compiler will do the
optimization while compiling - so it will compile to the same bytecode as
String myString = "first bitnext bit";But for the more general case where it is not constant strings, you are almost right.
The only difference is that in java 1.5 the compiler will use a StringBuilder - it’s just like StringBuffer, but without the synchronisation. With some JVM’s, this might make the + version marginally faster.
As well as more readable.
Now, if you start doing multiple concatenations in different statements, it is a different matter. In that case, using an explicit StringBuilder will save the jvm from constructing a lot of temporary StringBuilders.
It will be much faster to do
StringBuilder result = new StringBuilder();
for(int i = 0; i
than
String result = "";
for(int i = 0; i
March 23rd, 2006 at 11:37 am
Whoops - the parser ate my <’s.
Anyway, you get my menaing.
March 23rd, 2006 at 11:44 am
Yes
April 2nd, 2006 at 5:25 am
Hi
I am in urgent need for the program in java which compares two huge strings and return boolean value
Do help me by giving the appraoch and code
with regards
seenu
April 3rd, 2006 at 3:38 am
String.equals()
December 24th, 2006 at 12:09 pm
out.println(” user from form”);String name3= request.getParameter(”uname”);out.println(name3);
out.println(”user from DB”);String name1= rs.getString(”uname”);out.println(name1);
String test=name1;
out.println(”pass from DB”);String name2= rs.getString(”pass”);out.println(name2);
out.println(” pass from form”);String name4= request.getParameter(”pass”);out.println(name4);
if (name3.equals(name1))
{
out.println(”Authentication successful- usewwerwrwrname is correct”);
}
else {
out.println(”kindly check your usernasame and/or password”);
}
the above are my codes, i get the output in the jsp page as :
user from form krishna
user from DB krishna
pass from DB krishna
pass from form krishna
kindly check your usernasame and/or password
what is wrong in my statement… the strings are same, but the if clause is not executed.. will be kindful to know the answer..
January 26th, 2007 at 10:33 am
Krishna: you may want to make sure there’s no trailing spaces by doing:
if (name3.trim().equals(name1.trim()))…
Or even compare case-insensitively by using
name.toUpper(); // I think
At least if you want to be Microsoftish
otherwise I see not problems with your code… (other than calling passwords for “name” — be careful with variable names or it will come back and bite you some day… had a colleague that used zib and zob and variations thereof for his variable names… guess how fun that was to work with? ;o)
HTH
/Erik
March 1st, 2008 at 8:38 am
how to uncompare 2 strings??
if (arr3[u].equalsIgnoreCase(search))
is to compare
how about the right this??
if (arr3[u] NOT EQUAL TO (search));
what is tha code for that??
January 15th, 2009 at 3:41 am
jeh: you must be f* joking
April 28th, 2009 at 4:53 pm
HI,
I have a small question in java.
I have to inputs , which are word documents .I want to compare these two document values.Is it possible in Java.If any one knows this please let me know.
thanks & Regards,
A.Pushpanjali
April 28th, 2009 at 4:57 pm
HI,
I have a small question in java.
I have two inputs , which are word documents .I want to compare these two document values.Is it possible in Java.If any one knows this please let me know.
thanks & Regards,
A.Pushpanjali
April 29th, 2009 at 8:35 am
Here is your answer A. Pushpanjali
Java program for comparing two text files