tag:blogger.com,1999:blog-8712770457197348465.post2988234886187149875..comments2024-03-17T23:01:26.872-07:00Comments on Javarevisited: How to compare two String in Java - String Comparison Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-8712770457197348465.post-11145662122485792682017-12-26T22:28:33.580-08:002017-12-26T22:28:33.580-08:00Wow, great post.Wow, great post.Anonymoushttps://www.blogger.com/profile/14384252048920719168noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-86319461031971967312015-12-12T05:27:18.149-08:002015-12-12T05:27:18.149-08:00Imagine that you have an application that on a dai...Imagine that you have an application that on a daily basis imports data from some other system and loads data into the data base. On demand the system loads the data, all as strings, into memory and then holds them in memory while it converts some of them to integer or double or date and performs complex calculations on them. Now imagine that you are loading millions of rows when you do this. Anonymoushttps://www.blogger.com/profile/10939091044212106220noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-31739058086676908282015-05-05T14:21:40.029-07:002015-05-05T14:21:40.029-07:00Hi there, can you a explain more about why "=...Hi there, can you a explain more about why "==" is not good on compare two string whether they are "equals". Because Java is using String pool, which means one string will only have one instance in the pool but have many references. Looks like when using "==" to compare, as long as two string are both reference to the same string in string pool, the value is "Anonymoushttps://www.blogger.com/profile/03353776695016040743noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-33834759925672473942014-01-08T06:01:46.477-08:002014-01-08T06:01:46.477-08:00...and the above example can be extended with the ......and the above example can be extended with the following interesting lines:<br /><br /> final String s4 = s3.intern();<br /><br /> Assert.assertTrue(s1.equals(s4)); // passes<br /> Assert.assertTrue(s1 == s4); // passesZolar Systemhttps://www.blogger.com/profile/04342486759177430549noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-14460494587126908512014-01-07T23:36:52.480-08:002014-01-07T23:36:52.480-08:00@Test
public void test(){
StringBuilder sb =... @Test<br /> public void test(){<br /> <br /> StringBuilder sb = new StringBuilder();<br /> sb.append("a").append("b");<br /> <br /> String s1 = "ab";<br /> String s2 = "ab";<br /> String s3 = sb.toString();<br /> <br /> Assert.assertTrue( s1.equals(s2) ); // passes<br /> Assert.assertTrue( s1==s2 ); // passes<br /><br /> Zolar Systemhttps://www.blogger.com/profile/04342486759177430549noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-42954745841592920002013-08-13T22:01:42.430-07:002013-08-13T22:01:42.430-07:00I see all these methods compare Strings alphabetic...I see all these methods compare Strings alphabetically, is there any other way to Compare String in Java, which can compare Strings based upon custom logic?Gramenoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-3334691317081173162013-05-03T00:29:01.709-07:002013-05-03T00:29:01.709-07:00If 2 Strings are intern, then we can use "==&...If 2 Strings are intern, then we can use "==" to comapre strings. By default String literal are intern. So we can use "==" to comapre strings.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-35245948403576360882013-04-15T19:07:35.779-07:002013-04-15T19:07:35.779-07:00if(array[0].equals(""))
what the use of ...if(array[0].equals(""))<br />what the use of quotation ? pls help..userhttps://www.blogger.com/profile/17693247259284909983noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-10490510112545821352013-01-25T09:40:32.050-08:002013-01-25T09:40:32.050-08:00you better use patter matching ... by using regula...you better use patter matching ... by using regular expression ...Anonymoushttps://www.blogger.com/profile/00045204650085096882noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-47336716938488729262013-01-23T02:16:24.745-08:002013-01-23T02:16:24.745-08:00String tv = "sony Bravia";
String televi...String tv = "sony Bravia";<br />String television = "sony is a leading innovative firm and has produced a master peice like Bravia which is ruling todays entertainment world";<br /><br />if we observe string TV it contains "sony bravia"<br />if we observe String television is contains "sony on the first place and then continued --- had has got "bravia"Hola Tomorrowhttps://www.blogger.com/profile/06694091840135376226noreply@blogger.com