How to manage Continuous Changing values in an array of strings [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 9 years ago.
Improve this question
I have an array of strings but the values in array is changing continuously changing.
Is there any other way of managing the array except removing items and changing index locations?
public int[] deviceId=null;
deviceId=new String[deviceCount];
in my case deviceCount is changing as new device comes. so i continuously need to change array size and add or remove items

Java offers a really handy mechanism known as the ArrayList. It's a dynamic array that you can use to do what you're describing.
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

Related

get non duplicate items from arraylist [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 1 year ago.
Improve this question
Need help! I have a Json file with string values. By clicking on the button, I put a random string from this file into the arraylist. But I shouldn't put duplicate elements in the arraylist. How can i do this? Thank you in advance.
Use a Set instead of a List. It does not allow duplicates. You can get more detailed information in the reference documentation: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Set.html.

Java foreach method from second element in LinkedList [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 5 years ago.
Improve this question
I need help with foreach method to LinkedList in Java 8.
I need to start from second element. I don't know how to do this.
You can skip the first element: list.stream().skip(1).forEach(...). Note that the skipped elements will still be traversed by the stream, so for a random access list such as ArrayList it is much more efficient to use a loop starting from the relevant index if this index is very large. In your case it doesn't matter because your starting index is small and your list doesn't support random access.

Java - Recursively Permute List Without For Loops [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 7 years ago.
Improve this question
I want to create a different way of permuting a list like [apple, banana, orange] without using for loops recursively that will work for any size list and input etc. I already created one with using for loops, but I can't figure out myself without using for loops to solve the problem as this second part of solving a permutation without a for loops recursively is also going to be a question on our next exam (study guide I am reading) any idea how I would tackle this so I can see and understand how it works for the next exam question?
You can emulate a loop by the following recursion:
do nothing for the empty list
otherwise
work on the first element
recurse, using the sublist that starts with the second element

how to implement non recursive inOrder traversal [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 want to do inorder traversal not using recursive and to put the nodes in an array given the size of the BSTmap, it is easy to use recursive put i need to put the nodes in an array !!
Does it have to be an array? If not, you could use a linked list to add and remove the nodes without needing to know the size of the BSTmap.

How to Create Strings Programatically in Java [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 8 years ago.
Improve this question
So I am creating a program that need to create as many strings and integers as the user says. The amount is stored in wordlength, and I need to create these strings programmatically based on the input. Can somebody help me?
First, ask the user to input how many strings to store. This can be done through a Scanner.
Then, make an array of type String with length equal to the user input number.
Then, fill in the array through a Scanner with a for loop.
I hope next time you search about you problem before you write a question about it.

Categories