Jay S

Jay S

  • NA
  • 230
  • 57.8k

C# List<T> in Java

Sep 8 2014 9:17 AM
Java noob here, coming from a C# background and having a couple of issues trying to re-write something in Java.


In C# I'd have something like this:


Main class:


            System.IO.FileStream cityInput = System.IO.File.Open(this.path, System.IO.FileMode.Open);
            System.IO.BinaryReader cityBr = new System.IO.BinaryReader(cityInput);
            long CityList = 10;
            this.Cities = new System.Collections.Generic.List<Cities>();
            int c = 0;
            while (c < CityList)
            {
                Cities item = new Cities(cityBr);
                this.Cities.Add(item);
                c++;
            }
            cityBr.Close();


And then my Cities Class:

namespace myObjects
{
    public class Cities
    {
        public byte cityAttraction;
        public short cityID;
        public  Cities()
        {
        }

        public Cities(System.IO.BinaryReader reader)
        {
this.cityAttraction = reader.ReadByte();
this.cityID = reader.ReadInt16();
        }
    }
}

I have been able to write my own binaryreader class in java based on some code i found in github.


My issue that I cannot work out is how to create a generic list collection based on a class in java.


Any help/direction/example would be great.

Answers (1)