+ 1
Java string slice
please i have been try to slice a string on java but the statement are not correct can anyone tell me where i have made a mistake. var name = "caleb"; var cutName = name.slice(0,1); System.out.println(cutName);
7 Réponses
+ 2
Java String does not have a slice() method.
You can use substring() instead.
You can check the list of all available String methods in the documentation.
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/String.html
+ 2
Javascript does not have System.out.println :)
Please make up your mind which language you want to code in 😅
And attach a link to your code for testing.
+ 1
sorry i meant javascript
+ 1
Arham Sami actually, Java does have var keyword. It is called type inference. The compiler will try to guess the type of the variable, if it can be decided from the value of the assignment.
+ 1
Thanks, I didn't knew I thought Java was statically typed
0
Java doesn't have "var" Keyword and slice method
0
Yes it is still statically typed. Type inference happens during compilation.
And there are plenty of restrictions for "var". you cannot use it in function signatures or fields, only for local variables. And use must use an assignment immediately, you cannot declare a variable with "var" type not giving it a value.
So it's not exactly the same as in Javascript.