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.
Related
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.
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 2 years ago.
Improve this question
Example
if there are 4 slots named A1,B1,C1,D1. If first user enters A1 and when the second user enter the same slot it should error it has already been chosen.
The built-in class java.util.HashMap can do that. Read the docs, perhaps search for some usage examples :)
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
How to make TextField that inputs letter than compares it with string? It's Hangman game.
The field itself would not do any of the comparing, it will act only as an input access point. That would mean that the only thing it will do is gather whatever you type in it.
So how do you actually make the comparison? Well you will have to call an underlying method, every time there is something written in the field.
for that method you could use some of Java's build in String functionalities for example you could use:
string.indexOf('a').
If the a is present in string, it returns the index(>=0). If not, it returns -1. So, a non-negative return value means that a is present in the string.
You can use Java Swing to create the UI.
There is a TextBox (JTextField). But mostly the Textbox itself will not write anything in it. A user has to do the writing.
You would like to make it only possible to add one char at a time or you have to check if the text the user entered is at most one char.
After that you can check if the char exists in the word you are looking for.
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
I want to implement a functionality in java where I can search by both by username or by employee number within a single search bar.
I am looking for a simple solution either at client side or at java side
Thanks in advance
Just perform the first search, if it gives a result use it. If not then do the second search.
If usernames must contain alphabetic characters and employee numbers cannot contain them then you could look at the contents of the string and decide which search to run based on that.
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