Java is very strange at times. It's super easy to make an array of characters into a String when you make a new String, but a pain to do so afterwards.
Umm, what about String.toCharArray - how is that a pain to use?
Java is very strange at times. It's super easy to make an array of characters into a String when you make a new String, but a pain to do so afterwards.
Umm, what about String.toCharArray - how is that a pain to use?
That is making a string into an array of characters, not the other way around (what he is asking for).
Regardless, I have no clue why he can't just make a new String to turn that array of characters into a string. Not that hard. He's probably just annoyed that char[].toString() returns the Memory address rather than a string with the content of that array.
Oh, right. I misread his post; I thought he wanted to change the String back into an array of characters after it was created.
However, now that I read it again, what he wants (being able to put an array of characters into a String after it has been created) is not only unnecessary (because using the constructor works fine), but it would violate some very basic principles of the language - a Java String is immutable.
If you want to modify a String-like object after its creation, use a StringBuffer. With one of those, you can use append to append an array of characters.
George, could you clarify what you were trying to do?
The issue of what char[].toString() does is an interesting one, though.
The way things are in Java, there is some trouble to do with the fact that there are primitive types, but the rest of the language remains heavily object oriented. Arrays in Java are also quite poorly implemented from an object-oriented perspective - they're kind of half-object, half-primitive.
Another interesting issue with Java is the implementation of generic types, specifically the use of type erasure. On the whole, it works, but you run into issues when you end up mixing generics with arrays, because of the aforementioned dodginess of arrays. If Java was fully object-oriented, generics would be fine.
Because of the dodginess of arrays, much of the functionality that otherwise ought to be inside an actual array class is actually provided within java.util.Arrays. It's also quite noticeable that any method needing to work with arrays needs to provide a method for each different type of array. However, even though there is a java.util.Arrays.toString(char[]) method, if you do java.util.Arrays.toString("abc".toCharArray()), the result will not be "abc" but, in fact, "['a', 'b', 'c']". The reason it works like this is because even though in practice Java distinguishes between different array types, in theory they would all be in one class and so the method is expected to work in the same way for a char[] as it does for any other array.
These issues I mentioned with Java could be fixed if everything was a proper object - i.e. no primitive types, and arrays work as they ought to. However, that would break backwards compatibility, and that is extremely important in Java.
However, I don't see an issue when it comes to converting between a char[] and a String.
He's probably just annoyed that char[].toString() returns the Memory address rather than a string with the content of that array.
Yeah, that was really annoying.
However, now that I read it again, what he wants (being able to put an array of characters into a String after it has been created) is not only unnecessary (because using the constructor works fine), but it would violate some very basic principles of the language - a Java String isimmutable.
Well due to the way the code was structured, I had to return a String, but due to complicated IF structures the compiler was saying I'd never initialized the variable. I could make a temporary variable (and did) but that solution just annoyed the crap out of me.
Anyway, I found the answer I needed. String.valueOf(char[])
Strange. String.valueOf(char[]) will still make a new String object and return it, so it shouldn't be any different from new String(char[])
Yes, technically you are correct. You have to understand though. What I need for my code was a variable that I could assign as I pleased that held a string of characters, not an immutable String object. What Java is actually doing behind the scenes is of little concern to me, it gets me where I need to go and using a StringBuffer would be far more trouble than it's worth for this problem.
You can assign a variable to a different string either way, because the variable is a reference to the object, not the object itself. You don't need a StringBuffer for that.
To all of you that say school didn't provide you with any real knowledge: I can only speak for myself, but elementary school, high school and college all provided me with valuable knowledge, thought processes, writing and communication skills, typing (very helpful in getting jobs) and computing skills (though rudimentary compared to most here, I am usually the "tech savvy" person in every office I have ever been in), etc. Not to mention that these institutions, for better or for worse, were invaluable to my social development.
if incredibly easy you mean counter-intuitive to every text editor made in the last ten years. And how exactly is a text editor "powerful?"
How is it counter-intuitive to have a powerful interface? I can't do inline steam editing with regular expressions in word or GEdit. For the kinds of text manipulation I do a a daily basis, vi is unparalleled, and saves me a great deal of time.
Of course, it's not for everyone. If the above are the problems you're having in Java, that's probably not for you either. ;^) I'd suggest using Python or some other scripting language rather than Java for whatever it is you're doing.
What I'm doing is simple changes to a config file, for this Vi is super overkill and just flat out frustrating.
For someone like me, vi is the fastest way to do that. Or, if I know exactly what I'm changing, I don't even use a text editor at all: just a stream editor like sed.
Besides, if you're just editing a config file, what's the problem? As long as you know how to save, exit, and go into Insert mode, you're good. Don't need to know anything else. Any computer tech in the world should at least know vi that well.
For someone like me, vi is the fastest way to do that.
For you who know exactly what you're doing and with years of experience. Who has less than a year of experience with *NIX OSes and who's just fiddling with Oracle to try and make external doc parsing work again. We upgraded to 11G and things are just being difficult.
Besides, if you're just editing a config file, what's the problem? As long as you know how to save, exit, and go into Insert mode, you're good. Don't need to know anything else. Any computer tech in the world should at least know vi that well.
It just frustrates me is all. Never really had any experience on training with Linux.
We upgraded to 11G and things are just being difficult.
The 11g client seemed to have trouble with our 10g server, so I downgraded. Of course, I was doing some ODBC with a funky virtual IP setup, which complicated things, so I can't say for sure if it was the 11g client or my network at the time.
The 11g client seemed to have trouble with our 10g server, so I downgraded. Of course, I was doing some ODBC with a funky virtual IP setup, which complicated things, so I can't say for sure if it was the 11g client or my network at the time.
I'm fiddling with the 11G server right now. Something seems to have gotten unconfigged when we upgraded and no one remembers exactly how it's supposed to be. *Sigh* The joys of legacy systems.
In more "Tales of my old man not fucking listening to a thing I say" He did indeed follow my advice, and didn't get a thousand watt amp for practicing guitar. He instead got a thousand watt PA system with a mix board because it was cheaper. Dickhead.
In more "Tales of my old man not fucking listening to a thing I say" He did indeed follow my advice, and didn't get a thousand watt amp for practicing guitar. He instead got a thousand watt PA system with a mix board because it was cheaper.Dickhead.
In more "Tales of my old man not fucking listening to a thing I say" He did indeed follow my advice, and didn't get a thousand watt amp for practicing guitar. He instead got a thousand watt PA system with a mix board because it was cheaper.Dickhead.
Uwe Boll somehow got the rights to make a Metroid movie, and the fun doesn't stop there. Guess who they got to play Samus? Jessica Simpson. Yes, you did read that correctly. Jessica fucking Simpson. I didnn't really care about any of his other atrocities, but when he gets his franchis killing hands on one of my all-time favourite series, I will be seriously pissed.
Uwe Boll somehow got the rights to make a Metroid movie, and the fun doesn't stop there. Guess who they got to play Samus? Jessica Simpson. Yes, you did read that correctly. Jessica fucking Simpson. I didnn't really care about any of his other atrocities, but when he gets his franchis killing hands on one of my all-time favourite series, I will be seriously pissed.
I'm calling it now: We're going to see Samus's boobs. Possibly in the Phazon Mines. Uwe Boll is ze only genius in ze whole focking business, after all.
Uwe Boll somehow got the rights to make a Metroid movie, and the fun doesn't stop there. Guess who they got to play Samus? Jessica Simpson. Yes, you did read that correctly. Jessica fucking Simpson. I didnn't really care about any of his other atrocities, but when he gets his franchis killing hands on one of my all-time favourite series, I will be seriously pissed.
WHAAAAAAAAAAAAAAAAAAAAAAAAAAT?!!!!!!!!!!! DID HE PUT ANY THOUGHT INTO THIS AT ALL?!!! I imagine his thought process was "Okay, Samus is a blonde and very pretty. I'VE GOT IT!! JESSICA SIMPSON!!! She is both pretty and a blonde. There is no one else who can play her -stupid grin-." Even though she is not much when it comes to being an actor, Angelina Jolie is light-years ahead of Jessica Simpson as being a better match for Samus; and that says something when it's me saying that as I despise Jolie.
Nintendo must have been bribed with gobs of cash, because they wouldn't give up the rights to something like Metroid that easily. I don't think they had any idea who Boll was at all or his past history. What boggles my mind is how Boll is able to stay in the business when he gets so much backlash from both sides of the spectrum. Is he evil or incompetent (or both)?
Uwe Bollisze only genius in ze whole focking business, after all.
I agree with him, he's the only genius in the business. But what he's a genius at, well, that's something we disagree on, because he thinks that it's filmmaking.
Uwe Bollisze only genius in ze whole focking business, after all.
I agree with him, he's the only genius in the business. But what he's a genius at, well, that's something we disagree on, because he thinks that it's filmmaking.
Comments
Regardless, I have no clue why he can't just make a new String to turn that array of characters into a string. Not that hard. He's probably just annoyed that char[].toString() returns the Memory address rather than a string with the content of that array.
However, now that I read it again, what he wants (being able to put an array of characters into a String after it has been created) is not only unnecessary (because using the constructor works fine), but it would violate some very basic principles of the language - a Java String is immutable.
If you want to modify a String-like object after its creation, use a StringBuffer. With one of those, you can use append to append an array of characters.
George, could you clarify what you were trying to do?
The way things are in Java, there is some trouble to do with the fact that there are primitive types, but the rest of the language remains heavily object oriented. Arrays in Java are also quite poorly implemented from an object-oriented perspective - they're kind of half-object, half-primitive.
Another interesting issue with Java is the implementation of generic types, specifically the use of type erasure. On the whole, it works, but you run into issues when you end up mixing generics with arrays, because of the aforementioned dodginess of arrays. If Java was fully object-oriented, generics would be fine.
Because of the dodginess of arrays, much of the functionality that otherwise ought to be inside an actual array class is actually provided within java.util.Arrays. It's also quite noticeable that any method needing to work with arrays needs to provide a method for each different type of array. However, even though there is a java.util.Arrays.toString(char[]) method, if you do
java.util.Arrays.toString("abc".toCharArray()), the result will not be "abc" but, in fact, "['a', 'b', 'c']". The reason it works like this is because even though in practice Java distinguishes between different array types, in theory they would all be in one class and so the method is expected to work in the same way for a char[] as it does for any other array.
These issues I mentioned with Java could be fixed if everything was a proper object - i.e. no primitive types, and arrays work as they ought to. However, that would break backwards compatibility, and that is extremely important in Java.
However, I don't see an issue when it comes to converting between a char[] and a String.
Anyway, I found the answer I needed. String.valueOf(char[])
String.valueOf(char[])
will still make a new String object and return it, so it shouldn't be any different from
new String(char[])
In fact, that's probably what the source code looks like:
public static String valueOf(char[] data) {return new String(data);}
I can only speak for myself, but elementary school, high school and college all provided me with valuable knowledge, thought processes, writing and communication skills, typing (very helpful in getting jobs) and computing skills (though rudimentary compared to most here, I am usually the "tech savvy" person in every office I have ever been in), etc. Not to mention that these institutions, for better or for worse, were invaluable to my social development.
Ewwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww.
EDIT: The only "power" I see to Vi is its ubiquity. I'd be using Nano right now if I could.
Of course, it's not for everyone. If the above are the problems you're having in Java, that's probably not for you either. ;^) I'd suggest using Python or some other scripting language rather than Java for whatever it is you're doing.
Besides, if you're just editing a config file, what's the problem? As long as you know how to save, exit, and go into Insert mode, you're good. Don't need to know anything else. Any computer tech in the world should at least know vi that well.
Nintendo must have been bribed with gobs of cash, because they wouldn't give up the rights to something like Metroid that easily. I don't think they had any idea who Boll was at all or his past history. What boggles my mind is how Boll is able to stay in the business when he gets so much backlash from both sides of the spectrum. Is he evil or incompetent (or both)?