About 226,000 results
Open links in new tab
  1. java - Creating an Object inside a loop - Stack Overflow

    @SebastianH String a ="foo" here "foo" is a string literal and stored in java string pool. if you try to assign same literal into another reference, it will get same reference from string pool. but new string(..) returns a object of string type

  2. Create variable names using a loop in Java? - Stack Overflow

    Jul 24, 2010 · first time poster, long time reader so be gentle with me :) See the following code which works to generate me timestamps for the beginning and end of every month in a financial year. int year = 2...

  3. How would I create a new object from a class using a for loop in …

    Oct 1, 2013 · I have a class named Card and I have this for loop: int i; for (i = 0; i < 13; i++) { Card cardNameHere = new Card(); } What I want to do is create new instances based on the for loop. So for example, I would like the names to be card1, card2, card3, etc. The number would come from the for loop. I have tried this and it does not seem to work:

  4. Declaring variables inside or outside of a loop - Stack Overflow

    Jan 10, 2012 · The scope of local variables should always be the smallest possible. In your example I presume str is not used outside of the while loop, otherwise you would not be asking the question, because declaring it inside the while loop would not be …

  5. how to create array inside for loop in java - Stack Overflow

    Mar 11, 2014 · In you code i is already defined within the scope of the for loop. Also as soon as you exit the loop, the created variables will be out of scope. Furthermore, variables beginning with an Integer are invalid in Java.

  6. Java Main Game Loop - Stack Overflow

    Aug 17, 2013 · Overall, it is a good loop, but there are a few missing aspects to what I have found in experience to be the best loop. You will eventually want to move to LWJGL or some other java game API, but for now, learn the basics of how game-loops work, and what best suits your needs. Firstly, in answer to one of your points, no.

  7. Java - Creating Multiple Threads with a For Loop

    Apr 14, 2015 · java ExecutorTest 2 Runnable started id:0 Run: pool-1-thread-1 Runnable ended id:0 Runnable started id:1 Run: pool-1-thread-2 Runnable ended id:1 Related posts: ( Advantages of using ExecutorService as a replacement for plain Thread) ExecutorService vs Casual Thread Spawner. How to properly use Java Executor?

  8. java - Can a for loop be written to create an infinite loop or is it ...

    Jun 14, 2011 · Just for fun (and this too long for a comment): a lot of people will be very surprised to learn that for a lot of very practical purposes the following is nearly an infinite loop: for (long i = Long.MIN_VALUE; i < Long.MAX_VALUE; i++) { ...

  9. Create several new objects within a for-loop in Java

    May 11, 2012 · I want to create several objects from a class in a for loop. but I don't know how to code it. What I have written creates a new object but it overwrites the previous object. package assginment1_ve...

  10. java - Creating multiple objects with different names in a loop to ...

    I am trying to create mutliple objects of a type of class I made. I then want to transfer these values into the array list. How can I create objects using a while loop that have different names. For example here is my code now, but it would only make an object of one name. Customer cust = new Customer("bob", 20.0);

Refresh