Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Sam Knowski

Greenhorn
+ Follow
since Dec 06, 2015
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sam Knowski

I believe I understand what you're asking.

Yes, strings are immutable. Unless the concatenated string is null, when you call the concat method you're getting a new String object.

Here's the concat method decompiled for your reference:

Have a look at some array examples to make sure that number = i is the correct way to set a value.

In your second example, there is actually a toArray() function for array list which would give you the ability to do what you want to do.
ArrayList toArray()
6 years ago

Winston Gutkowski wrote:
To understand recursion, you must first understand recursion.


I'm going to steal this
6 years ago

Lama Al Najjar wrote:Can I consider this: if the length of the string is equal to one or below, therefore I have put the "empty string case" into account ?


One of the beautiful things about programming is that you can give 10 developers the same problem, and they can give you 10 different, correct, solutions. There are approaches to solving this problem both with and without directly accounting for the empty string case and the single character space. I would certainly encourage you to find multiple solutions to this problem and go with the one you feel is the least complex.

To more directly answer your question, in your current solution I would recommend handling the empty string case. You are very close to a solution with your current code. bhshn bhwsr gave you a great hint on where to look to correct your code, so please read his post again and see if you can see the problem. Also, as Campbell mentioned, using return multiple times in the same method can create problem when you write larger programs down the road, so getting in the habit of avoiding that pattern can potentially save you some major headaches.
6 years ago

Campbell Ritchie wrote:Nothing is instantiated until run time. And that is not what lazy initialisation means. Lazy initialisation means that something is not initialised or only initialised partiallly when it is required. The opposite is eager initialisation which means it is initialised completely in advance of being required.
What does happen at compile time is that formulae which fulfil the definition in the JLS which Henry showed you of a constant expression are evaluated at compile time. Look at this silly little class:-You can compile it and print the bytecode like this:-
javap -c Print2_5
… getting this output:-Nowhere in there will you find any sign of 1 2 3 or 4. You will however find 2.5 in the statement numbered 3. That is because constant expressions are evaluated before compilation completes. That also means that if you have a public constant which is a comile‑time constant, you should never change it.

Additional: This is the relevant JLS section.



Thank you for clarifying Campbell, my mistake!
6 years ago
Did you set up an actual "tomcat" user?

Command would have been something like:

You can check if the tomcat user exists by grepping your /etc/passwd file
6 years ago

Campbell Ritchie wrote:And, Sam Knowski, welcome to the Ranch



Thanks!
6 years ago

Campbell Ritchie wrote:Welcome to the Ranch both of you.


Thank you!
6 years ago

Campbell Ritchie wrote:Please explain. What has lazy initialisation got to do with it?



Please correct me if I'm wrong, but from my understanding the local variable (final boolean flag = false) is instantiated at compile time. However, the two object references (Test().flag and this.flag) are instantiated lazily (during runtime) to save memory.

Therefore 2 will be recognized by the compiler as dead code, however 1 and 3 could not be recognized until runtime.
6 years ago
does the file /Users/isaac/Desktop/uploadFileTest_jsp/target/uploadFileTest_jsp-1.0-SNAPSHOT/data/manifest.mf exist?
6 years ago
flag is final, so the compiler is smart enough to know it's value won't change

To answer your question on why it's different, have a look at lazy instantiation in java
6 years ago
Have a look at String Split.

Here's an example somewhat similar to what you're doing:
6 years ago