Skip to main content

Posts

Showing posts with the label java char

Convert String Array to Collection

How to convert a String Array to a Collection? Before we get to know how to convert a String Array into a Collection. We might want to know more details about the two… What’s the difference between a String Array and a Collection? Collection: It’s a group of data manipulated as a single object. Technically, its an interface in java which is implemented by various other classes. Many of which you uses regularly. One of its implementations can be seen in an array. An array best defined by the Sun is “An array is a container object that holds a fixed number of values of a single type.” So by implementing Collection interface, an Array skips the code required for its implementation – that is now taken care by the Collection interface! Why would I want to  convert a String Array into a Collection A Collection contains “Objects” if you understand the language…An Object is more generic implementation of the data types. So in a Collection, you can have any type of Object…So while w...

Standard way to find a Character TYPE!

While we are processing Characters, it’s a very common practice that we use ASCII values… I still remember in my computer class if I had to find out a character is a capital letter or not I would compare it with its ASCII value   I have also seen these comparisons if (ch >= ‘a’ && ch <= ‘z’ || ch >= ‘A’ && ch <= ‘Z’) – This means our character is an ALPHABET if (ch == ‘ ’) – This means our character is a whitespace     Now this comparison is language specific…I mean it works for English and some other international languages but fails for others… If you are interested in having an internationally accepted Character Test Code ready then read on     Char cTest; If (Character.isLetter(cTest) – This mean cTest is an Alphabet If (Character.isDigit(cTest) – This mean cTest is a Digit If (Character.isSpaceChar(cTest) – This mean cTest is a Space   There is a very useful function called getType which can return meaningful c...