How to better track Indices in java (vs. Python) -


In Python you can store different types of different items in a list, however to reach them, The index should be done through a list or method.

With Python dictionaries, you can map the key for items so that you can always remember which index does not contain that item.

Python Dictionary is very easy to write:

even easier acces:

Similarly, I tried to do this in Java The same thing though I have found it more complicated:

  // This program assumes that the build of class and method // hashmap & lt; String, Boolean & gt; Mydic = new Hashmap & lt; String, Boolean & gt; (); Mydic.put ("item1", incorrect); Mydic.put ("item2", incorrect); Mydic.put ("item3", incorrect);  

And especially difficult to use:

  boolean localvar = mydic.get ("item1"); If (localvar) {mydic.remove ("item1"); Mydic.put ("item1", incorrect); } Else {localvar = null; }  

Now I am not trying to compare languages ​​and if I did, then Java would probably win to be honest. Although it seems counter productive to make a hash of items and prices, then they are put back in a boolean and then it is added and removed to change it right.

Now in the case of booleans I have the option of beatsets but what if things say, three possibilities instead of two possibilities

  item1, item2, item3   

I also have the possibility of possessing and syncing about the variable (it looks in python)

 

= 0, 1 , 2 list = [This is true, true] DEF walking (item 1, item 2, item 3, item list): item list [item 1] = false

I'm not sure Is if you Chana items can also use the list items [1] = false in Java. Although I mostly relate to memory requirements and the way things are most understandable for Java.

Any and all input is appreciated,

Yes, Java's Syntax In this context, Python's syntax is more word-of-mouth.
There really is not much to answer in fact. This is just how it is

This is a very good / standard way of coding in the Java world. I do not see anything wrong with it, or anything that can be very simple here.

  // This program is a class and method / hashmap < Belongs to building string, Boolean & gt; Mydic = new Hashmap & lt; String, Boolean & gt; (); Mydic.put ("item1", incorrect); Mydic.put ("item2", incorrect); Mydic.put ("item3", incorrect);  

About this note of yours ...

This program considers creation of a class and method

... OK, every java program has at least one class and at least one method, so it's OK too.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -