wood burning stoves 2.0*
The moose likes Java in General and the fly likes  convert a string into character array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark " convert a string into character array " Watch " convert a string into character array " New topic
Author

convert a string into character array

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

can any one convert a string into character array without even calling a single library function
its a challenge question, lets see how experts solve this problem ?
@rob,@jeff,@champbell.....


The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

I am no expert and I dont know the idea behind this question. One way I could think of is to use getBytes on string and then cast each of the bytes into a char. (Not sure how this would work for multibyte characters). I wouldn't really think too much about such questions because in a industry no one would expect you to write everything from scratch. APIs are meant for reuse and not to reinvent the wheel.


Mohamed Sanaulla | My Blog
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

naved momin wrote:...without even calling a single library function


What would be a "library function"? You mean, methods out of the Java API? Or any method (including methods of the Java API)?


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39095
    
  23
naved momin wrote: . . . its a challenge question, . . .
Sounds like a party trick which ought to go to Diversions.
@rob,@jeff,@champbell.....
Unwharranted flatthery whill geth yhou nowhhere
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

Campbell Ritchie wrote:
naved momin wrote: . . . its a challenge question, . . .
Sounds like a party trick which ought to go to Diversions.
@rob,@jeff,@champbell.....
Unwharranted flatthery whill geth yhou nowhhere

don't get me wrong guys i know, API is meant for reuse and there is no point in reinventing the wheels, but at least we should now how the invention happens, don't you think so ?
@campbell sorry, i m not a spell bee so most of the time i end up with spelling mistakes, hope you don't mind, but i literally make sure that people understands my question
Note: if any one is thinking that i m doubting on any of your's abilities then this is certainly not true, all i want is, is there a way to do this kind of thing,
and i now no one ask this kind of question , but i don't ask questions which interviewer ask, because i m not a job hunger, all i want is knowledge, so whatever questions i ask here or in any forums
whether questions are foolish or meaning full it is straight from my mind ......hope you understand :-|
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14195
    
  20

naved momin wrote:can any one convert a string into character array without even calling a single library function

Without any method from the standard Java API? No, that's not possible. Or do you just mean: without calling any methods in the String class? If it's the latter, then you could use reflection to get at the internals of the string.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Jesper de Jong wrote:
naved momin wrote:can any one convert a string into character array without even calling a single library function

Without any method from the standard Java API? No, that's not possible. Or do you just mean: without calling any methods in the String class? If it's the latter, then you could use reflection to get at the internals of the string.


This is where I was thinking that the API would be used- at least to get the contents of the String.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

naved momin wrote:can any one convert a string into character array without even calling a single library function


Not possible.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39095
    
  23
naved momin wrote: . . . i m not a spell bee so most of the time i end up with spelling mistakes, . . .
. . . and I can wind you up about them! Mwaahaahaahaahaa
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

Campbell Ritchie wrote:
naved momin wrote: . . . i m not a spell bee so most of the time i end up with spelling mistakes, . . .
. . . and I can wind you up about them! Mwaahaahaahaahaa

so the conclusion is "no" in one word ? .....thanks for your time and comments ...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39095
    
  23
And there we were, thinking you had found some magic trick and would show us it when we were all stumped!
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
LOL! Did I just get Trolled!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39095
    
  23
Praveen Kumar M K wrote:LOL! Did I just get Trolled!
Bad luck, no you didn’t.
 
GeeCON Prague 2014
 
subject: convert a string into character array