#Quick question regarding splits

14 messages · Page 1 of 1 (latest)

hollow hedge
#

What happens if you split a string by the first thing in that string. Like if you have R31 and you split it by ("R")

String[] registerInfo=registers[i].split("R");

would 31 be registerInfo[0] or would it be registerInfo[1]

#

in this case, registers[i] was R31

hollow bridge
#

lets try it

#

/run

import java.util.Arrays;
public class A {
  public static void main(String[] args) {
  System.out.println(Arrays.toString("R31".split("R")));
  }
}
gusty marlinBOT
#

Here is your java(15.0.2) output @hollow bridge

[, 31]
hollow bridge
#

@hollow hedge

hollow hedge
#

thank you

#

wait so does that mean, that its the second thing? cuz I see the comma there

#

even though theres nothing before the comma

hollow bridge
#

yeah first String is "" second String is "31"

hollow hedge
#

awesome, thank you. also pretty awesome to know that there is a bot here that runs java code, thats gonna be a major help for me in the future

grizzled pasture
#

since it split at that point, one side was empty hence the random comma