Results 1 to 8 of 8
- 02-08-2015, 07:54 PM #1
Member
- Join Date
- Oct 2014
- Location
- NEW DELHI
- Posts
- 41
- Rep Power
- 0
- 02-08-2015, 08:01 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: hwo to compare two char type values?
Perhaps Character.toLowerCase(c1) == Character.toLowerCase(c2)
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 02-08-2015, 08:05 PM #3
Senior Member
- Join Date
- Mar 2013
- Location
- Greece
- Posts
- 183
- Rep Power
- 9
Re: hwo to compare two char type values?
You could just convert them to string and then use the equalsIgnoreCase(String x) method..
Java Code:import java.util.*; public class Test{ public static void main(String args[]){ char a = 'x'; char b = 'X'; String temp = "" + a ; if(temp.equalsIgnoreCase(b+"")){ System.out.println("Equals"); } } }
- 02-08-2015, 08:08 PM #4
Member
- Join Date
- Oct 2014
- Location
- NEW DELHI
- Posts
- 41
- Rep Power
- 0
Re: hwo to compare two char type values?
Character means exactly? and do i have to import any class before using this function? and whats its return type?
Last edited by rahil.khan; 02-08-2015 at 08:12 PM.
- 02-08-2015, 08:10 PM #5
Member
- Join Date
- Oct 2014
- Location
- NEW DELHI
- Posts
- 41
- Rep Power
- 0
- 02-08-2015, 08:23 PM #6
Member
- Join Date
- Oct 2014
- Location
- NEW DELHI
- Posts
- 41
- Rep Power
- 0
Re: hwo to compare two char type values?
thnx jim829, it worked..
thanx ShadowWalker for your reply...
- 02-09-2015, 08:02 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: hwo to compare two char type values?
You bet; your 'solution' creates a StringBuilder (line #8), moves an empty String literal to it, adjusts it (by appending a single character) and creates another String. The same holds to line #9, and it calls a method that calls another method (in the Character class) and finally the garbage collector has to get rid of two StringBuilders and two Strings; there is no such thing as a free lunch when it comes to Strings ...
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 02-09-2015, 03:28 PM #8
Senior Member
- Join Date
- Mar 2013
- Location
- Greece
- Posts
- 183
- Rep Power
- 9
Similar Threads
-
fetch and compare display tag values
By Hepey in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 04-16-2012, 10:59 AM -
Compare substring to char
By Muskar in forum New To JavaReplies: 2Last Post: 11-21-2010, 08:24 PM -
How to compare char
By scottpush in forum New To JavaReplies: 2Last Post: 02-27-2010, 11:51 PM -
Compare a char
By Torgero in forum New To JavaReplies: 3Last Post: 02-01-2009, 03:24 PM -
Char type for first character typed?
By Sageinquisitor in forum New To JavaReplies: 3Last Post: 07-17-2007, 07:08 AM
Bookmarks