Note that there are some explanatory texts on larger screens.

plurals
  1. PO3-dimensions different types Map or List: List(ID=integer) of List(ID=integer) of int[]
    primarykey
    data
    text
    <p>I'm going to build a hotel table. But I'm having problems when trying to implement this in Java.</p> <p>My hotel has <strong>Level(<em>int id</em>)</strong> x <strong>Room(<em>int id</em>)</strong> x <strong>Field</strong>(<strong><em>String</strong> status, int counter</em>)</p> <p>The same <strong>in php</strong> would look like:</p> <pre><code>$level=1; $room=2; if(isset($hotel[$level][$room])) { print("Room: ".$level*100+$room); print(", Status: ".$hotel[$level][$room]['status']); print(", Total clients:".$hotel[$level][$room]['counter']); } </code></pre> <p>And this print returns me(if room exist): <em>"<strong>Room:</strong> 102, <strong>Status:</strong> Reserved, <strong>Total clients:</strong> 8";</em></p> <p>Now I want to have the same in JAVA.</p> <p>But the problem is, that I'm not able to build this:</p> <pre><code>int[][][] my hotel; </code></pre> <p>Because, I have the different types in my multi-dimensional array.</p> <p>I tried to make sth like this:</p> <pre><code>Map&lt;String, List&lt;String&gt;&gt; myHotel = new HashMap&lt;String, List&lt;String&gt;&gt;(); </code></pre> <p>Or:</p> <pre><code>List&lt;List&lt;List&lt;String&gt;&gt;&gt; myHotel; </code></pre> <p>But</p> <pre><code>out.println( myHotel.get(1).get(2).get("status") + "\n" + out.println(myHotel.get(1).get(2).get("status")); </code></pre> <p>Or even:</p> <pre><code>out.println("Status:" + myHotel.get(1).get(2).get(0) + "\tClients:" + myHotel.get(1).get(2).get(1) ); </code></pre> <p>Also how to put elements. I'm thinking about sth like: WHEN it's <strong>a MAP table</strong>:</p> <pre><code>myHotel.put(1).add(2).add(0, "Reserved")); // But better would be: // myHotel.put(1).add(2).add("status", "Reserved")); </code></pre> <p>Or WHEN it's <strong>a List</strong><code>&lt;List&lt;List&lt;String&gt;&gt;&gt;</code>:</p> <pre><code>myHotel.add(1).add(2).add(0, "Reserved")); // But better would be: // myHotel.add(1).add(2).add("status", "Reserved")); </code></pre> <p>Thanks for helping :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload