Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Belegung von Arrays

Empfohlene Antworten

Veröffentlicht

Hallo Leutz,

Hab da ne Frage die sich wohl allein durch Syntax-Hinweis erledigen lässt ... habs aber in Java Insel etc nicht gefunden.

Also, wenn ich ein Bool-Array anlege, sagen wir mal mit

boolean[] neuesArray;

dann steckt da zunächst der Wert null drin weils noch keine Instanz beinhaltet.

Nun möchte ich das Array auf Größe 100 instanziieren mit

neuesArray = new boolean[100];

Damit sind jetzt alle 100 booleans mit false standardmässig vorbelegt.

wenn ich aber nun true statt false haben möchte ... wie geht das syntaktisch?

In PL/1 gibts da was in der Art:

neuesArray = new boolean[100] {false};

oder

neuesArray = new boolean[100] {false, true}; //das würde abwechselnd true und false reinlegen

Also Frage... gibts das in Java? ... und wie siehts aus?

gibts das in Java?
Nein, gibt es nicht. Du musst dich selbst um die Belegung des Arrays kümmern.



  public static void main(String[] args) throws Exception {

    boolean[] newArray = new boolean[5];

    for(int i=0; i < newArray.length; i++) {

      newArray[i] = true;

    }

  }

Nein, gibt es nicht. Du musst dich selbst um die Belegung des Arrays kümmern.



  public static void main(String[] args) throws Exception {

    boolean[] newArray = new boolean[5];

    for(int i=0; i < newArray.length; i++) {

      newArray[i] = true;

    }

  }

Bei einem "kleinen" Array bzw. unterschiedlicher Belegung würde auch eine direkte Initialisierung Sinn machen;)


  public static void main(String[] args) throws Exception {

    boolean[] newArray = {true, true, true, true, false};

  }

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.