In Java is there a way I can put a value in a linkList = array[ ] string
(I don't know how to word it here what I have so far with my code)
* Example object 51 I want to equal Array [0];
// Project code below
public String getCardRank() {
String values[] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"};
return "RRR";
}
// this part is in another .java file
private String addCard(String var) {
int value; char second = var.charAt(0);
value = (int) second;
switch (value) {
} return "TEST";
}
Solution:-
Yes, to store Array of elements in LinkedList you can create a function to do so.
The logic doe the same would be:-
static Node arrayToList(int values[], int n)
{
Node root = null;
for (int i = 0; i < n; i++)
root = insert(root, arr[i]);
return root;
}
This will do the work for you.
In your case since you have created two seperate classes so you have to call the custom function from the place you want to access the LinkedList.
Other way you can wrok around is by creating an object
List<String> values = new LinkedList<String>();
Note:- if you have any doubt ping in the comment section i will help you.
Get Answers For Free
Most questions answered within 1 hours.