Getting a collection of successors in Java [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
In this method, I'm trying to get the collection of successors from the current one. This is for the Tents and Trees game in Java where I extract the pattern from a file to build the board. '%' represents a tree, '.' represents an empty spot, '^' represents a tent, '#' represents the grass.
public Collection<Configuration> getSuccessors() {
Collection<Configuration> successors = new LinkedList<Configuration>();
return successors;
//return new ArrayList<>(); // replace
}
I don't know if this is the right way, but it doesn't return anything when I run the program. What am I doing wrong?

You are creating an empty LinkedList and returning it. This LinkedList has 0 elements, so you return anything.
You need to insert something in the LinkedList.
I hope my answer will be helpful.

Related

Permutations of array with at minimum 1 element [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 17 days ago.
Improve this question
I am trying to produce all permutations of an array of size N (i.e. N = 9) with possible elements Z (i.e. Z = [0,1,2,3,4])
Duplicates are allowed, but there needs to be at least one. I am able to write the algorithm to go through all possibilities but the minimum of at least one of each of Z is the part I'm having trouble with.
Looking to do this algorithm in java. Can someone help?

How to access a specific array element in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to define specific numbers out of an array of 52 numbers so I can assign them an image (yes I am creating an applet). I don't think that code is necessary for any of you to answer this question. Any help would be fantastic.
I'm not sure I understand what you're asking. You can set an item in an array this way:
myArray[4] = 52;
That would set array index #4 (remember it's zero based so it's actually the 5th item) to the value of 52. Is that what you're looking for?

Groovy remove value from collection [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In groovy is there a specific way to remove a value from a collection. For example I have a list of form fields but two of them are hidden fields and I'm trying to figure out how to remove them from the collection. The two parameters I'm trying to remove are salesKey and topicSelection. Groovy newbie so code samples are most helpful
request.requestParameterMap.collect { key, value -> "$key: ${value[0].string}" }.join("\n")
key.remove("salesKey")
key.remove("topicSelection")
I think you could use findAll:
request.requestParameterMap.findAll { key, value ->
!( key in ["salesKey", "topicSelection"] )
}
Check out this answer.
Also, depending on your specific aims, there are a couple of other ways to remove a pair, including dropWhile (which is more or less iterating over your data struct) and minus (which isn't so much removing a pair as creating a new structure without the specified pair). Official doc here.

ArrayList does not give the get option to retrieve the data [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I create customer and computer arraylist from the existing cutomer and computer classes as belows
ArrayList<Customer> customer = new ArrayList<Customer>();
ArrayList<Computer> computer = new ArrayList<Computer>();
But I don't available to get option to retrieve the data. Can anyone solve this problem?
customer.get(i) i is the index.
computer.get(i)
You have get like this.
USE THIS METHOD AS SPECIFIED HERE. Read up on this stuff please!
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
get(int index)
Returns the element at the specified position in this list.
For Customer :
Customer ithCustomer = customer.get(i);(retrieve ith item in the customer list)

I need a three-valued logic in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have tried to return null as third value in my boolean function, but it won't compile. I need to return three values from my class method - true, false and null (for example). Is there any standard way how can I do it?
Please use an enumeration with three values defined. Hacking things together is no solution.
Similar question has been asked, it should help.
You can make your own POJO object with this logic in getXX() method. From your method return this POJO with value and test it in code.
Generaly, don't use null values as state indicators.

Categories

Resources