I’m currently programming with Java, I’m slowly getting better, however, I’ve started learning newer things, can any of you see where I’m going wrong with the code below?
Again, keep in mind this isn’t anywhere near finished, I know I can polish it up a lot, I just want to know how to get it to work, I’ve never used an iterator in Java before. The rest of it works fine, but I’m trying to iterate through the ArrayList, but using something like:
c1get(i = c1Temp);
This is the kinda thing that I want to get to work, but it doesn’t seem to be working for me, anyone got any way of solving my problem, anyone got any advice for me? - Keep in mind I’m new to this, I’m still in my first year of Computer Science and I don’t have as much time as I’d like to have to learn how to program well, but slowly I’m getting there, or at least I think I am.
Can anyone give me any good references/guides on how to learn OOP theory and how to apply it well, it doesn’t help that I’ve been told a few different things by a few different people. Both in university and out, I’m guessing it’s an ‘open’/debatable topic?
In general, I (having 4 years of experience with Java - also with enterprise technologies) suggest not to focus on Java too much. If it is required for your studies, learn it but don't get addicted to it. There are many downsides to Java that you can only see if you have experience with other languages and technologies and if you have managed to understand software engineering (including things like OOP) from a theoretical perspective. If you are currently doing your bachelor studies you won't see such things and I guess non of your instructors will tell you how bad Java can be for a lot of purposes. Learn it and learn it correctly and you will have a great foundation to learn other languages and also your studies should benefit from good Java coding skills.
Is there a specific reason you've opted to use an iterator? One good reason for example is if you wanted to remove elements of your list while you're iterating. If you simply want to just iterate over the list, it's generally better form to just use java's for-each construct. For example..
If the goal were to benefit him for coursework then no one should answer or provide troll answers such as my system.Exec('wc -l ' + fn) in some other java thread.
Then @tsuser1729 introduced a best-practise approach and all I did, was to clarify that "best-practise" depends on the version of Java. In Java 8 you want to use streams to iterate through collections.
Okay, so what I've decided to do is something more like:
while(i < 200){
c1.add(in.nextInt());
double temp = 0.00;
temp = c1.get(l);
// some random arraylist here
randomArray.add(temp);
i++;
}
Would this sorta solution be okay? Anyone see a way where I can improve this? - Doe it make a difference if I initialise (I'm British, I know in code, 9/10 of the time, everything uses American spelling, I know a lot of people would rather see the word initialize.) the temp variable inside or outside of the loop, I'd need to assign a new value to it every time the loop does loop, so does that make a difference?
Nevermind, I am sorry for asking for help, but after a lot of experimenting with things I'm not that confident with, I've got things to work, and work kinda okay, or at least I think, the point of the whole program is to use some of the tools that I've specified, like an ArrayList and a Scanner. But the whole point of this program was to read in data from a text file and then compute some of it and output it in the console, this was like a piece of coursework, but not really. By not really I mean this is a challenge piece of work that my lecturer has given us, I wanted to do it to try and challenge myself more than anything.
But thank you all for your help! :)
Also @Ohban thank you very much for the tip about using a regular expression, and how it's pointless and actually slower to use in this case scenario. But I knew that regular expressions are horrible to use in terms of readability, that's why when I have used them in the past, I have made a block comment above it, explaining what it does in detail.
I know .. All I was point out and this goes to the op too.. Is that be careful using.something your instructor hasn't talked about or shown.. Some of them are dicks .. Lol trust me I know this first hand.. XD