Check if String[index] is empty before throwing ArrayIndexOutOfBounds exception

Check if String[index] is empty before throwing ArrayIndexOutOfBounds exception

This probably is a silly question but I am missing something and just can't figure out what... Looking for a sensible way of checking whether given index exists or not in a String[] array

This probably is a silly question but I am missing something and just can't figure out what... Looking for a sensible way of checking whether given index exists or not in a String[] array

String is a representation of a K,V pair but sometimes V may be empty so possible string examples are:

Foo1:Bla1

Foo2:Bla2

Foo3:

Foo4:Bla4

public void constructPair(String string) {
    String[] split = string.split(":");
    ...
    if(split[index] != null) { } // nope
    if(!split[index].isEmpty() || !split[index].isBlank() { } //nope
    if(split[index].length() > 1) { } // nope
    ...
}

Or should i just wrap the whole thing in try {} catch() {} ? block and deal with the exception accordingly?

Edit: For clarity 'index' is just pseudo not actual variable name

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

How to convert an Array to String in Java?

In this post, you'll learn the various methods to convert an Array to String in Java

Java String – String Functions In Java With Examples

In this post, we will be discussing about a new concept, Java String. String is a sequence of characters. But in Java, a string is an object that represents a sequence of characters. The java.lang.String class is used to create string object.

How to fix “exception in thread main java.lang.stringindexoutofboundsexception string index out of range” errors

I'm trying to recreate the game of mastermind except a simplified version. I've been stuck on this one error and I don't know how to fix it.