Search:

Type: Posts; User: _lithium_

Search: Search took 0.10 seconds.

  1. Thread: Generics

    by _lithium_
    Replies
    21
    Views
    2,606

    Re: Generics

    Yeah I thought of doing that but then the issue is, he wants the index number to be displayed correspondingly. I got the get() working, so I can just For loop it and run up the index number to the...
  2. Thread: Generics

    by _lithium_
    Replies
    21
    Views
    2,606

    Re: Generics

    The main final task is to display what is left in the LinkedList, I'm just struggling to find an easy solution without actually just programming it into the code to say the actual ones that I know...
  3. Thread: Generics

    by _lithium_
    Replies
    21
    Views
    2,606

    Re: Generics

    import java.util.*;

    public class GenericStack<E>
    {
    private LinkedList<E> list = new LinkedList<E>();

    public void push(E item) //the parameter is an item of type E
    {
    ...
  4. Thread: Generics

    by _lithium_
    Replies
    21
    Views
    2,606

    Re: Generics

    Well I've been trying to get the get() method working but keep getting errors with the:
    public int get(E item)
    {
    return list.get(item);
    }

    I can't figure out how to basically get the index...
  5. Thread: Generics

    by _lithium_
    Replies
    21
    Views
    2,606

    Re: Generics

    EDIT:::

    Got it, I'm dumb and forgot the -1 indicates that the value wasn't found. Forgot to place the index call after the push().
  6. Thread: Generics

    by _lithium_
    Replies
    21
    Views
    2,606

    Re: Generics

    Since I am supposed to be able to find the index number of the item, I know I need to use the indexOf() but can't figure out how to implement it into my app.

    public int index(E item)
    {...
  7. Thread: Generics

    by _lithium_
    Replies
    21
    Views
    2,606

    Re: Generics

    Any idea on how to configure peek()?
  8. Thread: Generics

    by _lithium_
    Replies
    21
    Views
    2,606

    Re: Generics

    That worked like a charm! thank you!


    :::EDIT:::
    How do I use the peek() then?
  9. Thread: Generics

    by _lithium_
    Replies
    21
    Views
    2,606

    Re: Generics

    Lol, I can't figure out how to get it to send me back the size or in fact, I can't figure out ANY of the peek(),pop(),size()...
  10. Thread: Generics

    by _lithium_
    Replies
    21
    Views
    2,606

    Generics

    So I'm completely stumped..

    this is the goal:
    1. Start a new class named GenericStack that specifies a type variable that provides for generics.
    2. Declare a linked list that will hold the...
Results 1 to 10 of 10