Skip to content

Tag: arrays

How to Convert an String array to an Int array?

I have made research for a couple hours trying to figure out how to convert a String array to a Int array but no luck. I am making a program where you can encrypt a message by using three rotors. I am able to type a message and get the index number for the first rotor (inner rotor) to encrypt

Java slice array as in python

I have an byte array in Java and need to get parts of it. I wanted to work with Java arrays in the same way as I work with Python list, using slices. There is something similar to this in Java? Thank you in advance. Answer You can use Arrays’ (https://docs.oracle.com/en/java/javase/14/docs/api/java.base…

Length of Array returning wrong number? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 6 y…

Java Array vs Scala Array

Seems one difference between Java Array and Scala Array is Java Array is co variant. Scala Array is not. Both are mutable. In java, sort method can take different arrays, such as arrays of String or Int. This is often quoted as a good example of Liskov substitution principle. Seems a good design to me? In Sca…

Java – Slice any array at steps

In python we are able to do the following: Is there an equivalent to this in Java? I have been looking for this type of array slicing, but I have had no luck. Any help would be great, Thanks! Answer If you are using Java 8, then you can make use of streams and do the following: Outputs: [0, 3,

Capitalization of the words in string

How can I avoid of StringIndexOutOfBoundsException in case when string starts with space (” “) or when there’re several spaces in the string? Actually I need to capitalize first letters of the words in the string. My code looks like: Tests: Input: “test test test” Output: “…