List class implementation

I want to inplement a list, it contains some records, and each record has got a few fields, and one of the fields is key.
I need the records be sorted by the key field, and certain record can be covieniently located by the key. And basically I need some method like 'add', 'delete', etc.
Which class shall I take as the father class, or is there any class I can use directly?
Example code is very aprrecialted if available.

See "SortedMap" interface. This should solve your problem of key-value pairs and it has put() and get() methods for adding and removing elements. The elements are sorted by their key.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/SortedMap.html
This should help.
Annie

Similar Messages

  • Implementation of Linked List class

    I am trying to implement the Linked List class for one week, but I couldn't figure it out. If you know, please let me know.

    Here is an example of a linked list. Hope that will help.
    // define a node of a linked list
    public class Node
    public int data; // point to data
    public Node next; // pointer to next node or point to null if end of list
    // listTest1
    public class ListTest1
    public static void main(String[] args)
    Node list;
    list = new Node();
    list.data = 3;
    list.next = new Node();
    list.next.data = 7;
    list.next.next = new Node();
    list.next.next.data = 12;
    list.next.next.next = null;
    Node current = list;
    while (current != null) {
    System.out.print(current.data + " ");
    current = current.next;
    System.out.println();
    // other listnode
    public class ListNode
    public int data;
    public ListNode next;
    public ListNode()
    // post: constructs a node with data 0 and null link
    this(0, null);
    public ListNode(int value)
    // post: constructs a node with given data and null link
    this(value, null);
    public ListNode(int value, ListNode link)
    // post: constructs a node with given data and given link
    data = value;
    next = link;
    Contents of ListTest2.java
    public class ListTest2
    public static void main(String[] args)
    ListNode list = new ListNode(3, new ListNode(7, new ListNode(12)));
    ListNode current = list;
    while (current != null) {
    System.out.print(current.data + " ");
    current = current.next;
    System.out.println();

  • Using List Class in java.awt / java.util ?

    have a program that:
    import java.util.*;
    List list = new LinkedList();
    list = new ArrayList();
    ... read a file and add elements to array
    use a static setter
    StaticGettersSetters.setArray(list);
    next program:
    import java.awt.*;
    public static java.util.List queryArray =
    StaticGettersSetters.getArray();
    If I don't define queryArray with the package and class, the compiler
    gives an error that the List class in java.awt is invalid for queryArray.
    If I import the util package, import java.util.*; , the compiler
    gives an error that the list class is ambiguous.
    Question:
    If you using a class that exists in multiple packages, is the above declaration of queryArray the only way to declare it ?
    Just curious...
    Thanks for your help,
    YAM-SSM

    So what you have to do is explicitly tell the compiler which one you really want by spelling out the fully-resolved class name:
    import java.awt.*;
    import java.sql.*;
    import java.util.*;
    public class ClashTest
        public static void main(String [] args)
            java.util.Date today    = new java.util.Date();
            java.util.List argsList = Arrays.asList(args);
            System.out.println(today);
            System.out.println(argsList);
    }No problems here. - MOD

  • Class implementation for interface

    Hello,
    I am a beginner in ABAP Objects.
    In the coding of method if_swf_ifs_workitem_exit~event_raised of class CL_SWF_UTL_EXIT_NEW
    There is the instruction follow :
    *Get the workflow container
    irh_container ?= im_workitem_context-> get_wf_container()
    Im_workitem_context is interface type  "IF_WAPI_WORKITEM_CONTEXT"
    If I execute in debug mode I see the implemtation class of this interface (im_workitem_context)  is "CL_SWF_RUN_WORKITEM_CONTEXT"
    But where this information of implementation is defined ? (I saw nothing)
    Regards
    Christine
    Edited by: chris_75 on Sep 7, 2010 4:22 PM

    Interfaces allow to implement highly scalable object oriented applications.
    Interface is a kind of a template for a real class which forces this class to implement methods defined in an interface.
    The main characteristics of an interfaces are:
    - they DO NOT contain any implementations (so there is nothing like INTERFACE ... IMPLEMENTATION - they have only DEFINITIONS - implementations are within classes)
    - they have only PUBLIC sections.
    Why we need an interface. The answer is simple:
    We want to handle some objects uniformly from one application compotent, whereas these objects may behave differently inside.
    Example:
    Let's say we need to build a sorting program for numbers.
    The program would have an interface variable L_RIF_SORTER of an interface LIF_SORTER. LIF_SORTER has a method definition SORT with an C_TAB changing parameter.
    Sorting application would call the sorting algorithm as follows:
    L_RIF_SORTER->SORT( CHANGING c_tab = l_tab ).
    Now is the main point:
    We want to have 2 kinds of sorting algorithms implemented, let's say BUBBLE SORT and QUICK SORT.
    To do so, we implement 2 classes: LCL_BUBBLE_SORT and LCL_QUICK_SORT.
    Both classes implement interface using the statment INTERFACES in a public section.
    The user would have to choose the algorithm from an input field. Depending on the content of this field the sorting application would instantiate one class or the other using the statement:
    CREATE OBJECT l_rif_sorter TYPE (variable_with_class_name).
    THis is the point where ABAP gets to know the real object and its type behind the interface.
    This approach is generally called the STRATEGY PATTERN. See Wikipedia for this.
    I hope I answered your question.
    Regards,

  • How can I read the filter dependent values in abap class implementation ?

    Hi Experts,
    I need read the filter dependent values in my Z Class implementation but I don´t know how to do it.
    In classic badi was via FT_VAL parameter.
    Now how can I do it ?
    Regars,
    Bala

    Rogerio,
    In case of badis the field flt_val gets added automatically as an import parameter when you check FILTER DEPENDENT check box. This is to restrict which implementation of the badi should be executed, if there are more than one.
    There is no such concept when you are building a class.
    If you want one of your methods to be executed on in certain cases, you need add the required logic within the method.
    If you are referring to the FILTER check box in the pic below, that is used for a different purpose. It is used to filter what is displayed on the class builder screen. F1 on the field to know more about the same.
    Thanks,
    Vikram.M

  • Internal class implementing interface extending abstract interface :P

    Confused ha? Yeah me too. RIght here it goes.
    Theres an abstract interface (abstractIFace) that has for example method1() method2() and method3(). There are two other interfaces iFace1 and iFace2 that extend abstractIFace. Still with me? :P iFace1 only uses method2() whereas iFace2 uses method1(), method2() and method3(). Internal classes implementing these are then used. The reason is so that when returning an object one method can be used that will return different types of objects. But this doesnt work. It says that all the classes in the abstractIFace must be used/implemented but I only want method2() in iFace1 and all in iFace2.
    Just say what the f*ck if this is too confusing cos i think it is and i did a crap job explaining!! :P

    public interface IFace {
        void method1();
        void method2();
        void method3();
    public class Test {
        private static class Class1 implements IFace {
            public void method1() {
                System.out.println("method1");
            public void method2() {
                System.out.println("method2");
            public void method3() {
                System.out.println("method3");
        private static class Class2 implements IFace {
            public void method1() {
                throw new UnsupportedOperationException();
            public void method2() {
                System.out.println("method2");
            public void method3() {
                throw new UnsupportedOperationException();
        public static IFace createObject(boolean flag) {
            return flag ? (IFace) new Class1() : new Class2();
    }

  • Steps  and Check list SNC implementation

    Dear Experts.
    Believe that you'll spend some time to put your precious quotes on this query.
    1. How SNC implementation should be done, what are the steps to be carried out?
    2. What are the Pre-requisites and check list for implementation?
    3. What testing needed to be done after implementation.
    Thanks in advance
    Vinoth

    Hi Vinoth,
    Responsibilities:
    BASIS / Security :
    1. System Upgrade / Installation
    2. Post upgrade activities like SPAU (if its upgrade), notes that are required to be implemented.
    3. Email / SMS set-up (Exchange infrastructure)
    4. Work-out the authorizations that need to be provided for different Business roles
    XI / PI :
    1. Download the content for latest SNC release
    2. Set-up communication between ERP <> XI <> SNC
    3. Check SLDCHECK
    4. Configuration scenario e.g. Sender Agreement, Receiver Agreement, Receiver Determination, Interface Determination, etc.
    Functional :
    1. Master Data set-up
    2. Required customizing
    Hopefully, this should give an overall idea.
    Regards,
    Sandeep
      Re: What are the ODM components available in SNC?  
    Posted: Aug 6, 2010 10:39 AM    in response to: Sandeep Mandhana           Reply 
    Hi Nikhil & Sandeep,
    Thanks for your valuable information.
    Could you please let me know the checklist and steps that should be followed while implementing SNC.
    Basis/Security peoples responsiblities?
    XI/PI peoples responsibilites?
    Functional peoples responsibilities?
    Thanks in advance
    vinoth

  • Can a class implements more than one interface?

    Hello
    Can a class implements more than one interface?
    Thanks

    Of course, this doesn't mean that it won't be a problem though. If the two interfaces have methods with the same signature, but different return types, you won't be able to implement them together. I.E.
    interface InterfaceA {
      public int doSomething(String myString);
    interface InterfaceB {
      public String doSomething(String myString);
    // Now the classes
    // Gives error "Duplicate method doSomething(String) in type ClassA"
    public class ClassA implements InterfaceA, InterfaceB {
      public int doSomething(String myString) {
        System.out.println("A");
        return 0;
      public String doSomething(String myString) {
        System.out.println("B");
        return 0;
    // Gives error "The return type is incompatible with InterfaceB.doSomething(String)"
    public class ClassB implements InterfaceA, InterfaceB {
      public int doSomething(String myString) {
        System.out.println("A");
        return 0;
    // Gives error "The return type is incompatible with InterfaceA.doSomething(String)"
    public class ClassC implements InterfaceA, InterfaceB {
      public String doSomething(String myString) {
        System.out.println("B");
        return 0;
    }

  • How can i call java class implemented as service from ExtJS after successfull activation of a page ?

    Hi ,
    I want to call a java class implemented as a service in felix . This should be called after succesfull activation of the page .
    I want to use ExtJs implemented in /libs/cq/ui/widgets/source/widgets/wcm/SiteAdmin.Actions.js file CQ.wcm.SiteAdmin.activatePage method.
    Please suggest something on this .

    Hi Sham ,
    i tried this ,
    var response = CQ.HTTP.post(
            CQ.shared.HTTP.externalize("/bin/replicate.json"),
            callback,
            { "_charset_":"utf-8", "path":paths, "cmd":"Activate" }
    if (CQ.HTTP.isOk(response)) {
         CQ.HTTP.post("/bin/sample.json",
                  null,
                  {"_charset_":"utf-8","path":paths});
    It is giving an alert messege on siteadmin screen as "Unspecified Error" .
    What can be the problem , am i missing something here?

  • Error "You may only define methods within "CLASS class IMPLEMENTATION"

    We have code in LMIGOSMC so that the vendor batch number appears in the MIGO transaction for certain movement types.  We have created another, custom movement type in which this functionality should be available so I need to add it to LMIGOSMC.  When I go in and try to make the modification I am getting the following error:
    "You may only define methods within "CLASS class IMPLEMENTATION ...ENDCLASS".
    What am I doing wrong?

    Hi,
    You are not doing anything wrong with regard to the syntax error you are getting.  During the syntax check of include program LMIGOSMC, the system is not aware of the CLASS... ENDCLASS statements within the program LMIGOSM4.  Try the syntax check at the LMIGOSM4 program level (or even better, at the SAPLMIGO level) and you will see that the error is not given.
    Regards,
    Jamie

  • Is there any statement to indentify if a class implements an interface?

    Is there any statement to indentify if a class implements a particular interface?

    If you want to check if a class implements an interface, look up the interface here:
    http://java.sun.com/j2se/1.4.2/docs/api/index.html
    and look under "All Known Subinterfaces:"
    If you want to check if an object is of that interface:if(yourObject instanceof SomeInterface)
        // do something
    }

  • Implementing constructor outside class implementation..

    REPORT  ZTUSH.
    CLASS counter DEFINITION.
      PUBLIC SECTION.
        METHODS CONSTRUCTOR.
        CLASS-METHODS: set IMPORTING value(set_value) TYPE i,
                 increment,
                 get EXPORTING value(get_value) TYPE i.
       PRIVATE SECTION.
       CLASS-DATA count TYPE i.
    ENDCLASS.
    METHOD CONSTRUCTOR.
    WRITE:/ 'I AM CONSTRUCTOR DUDE'.
    ENDMETHOD.
    CLASS counter IMPLEMENTATION.
    METHOD set.
        count = set_value.
      ENDMETHOD.
    ENDCLASS.
    DATA cnt TYPE REF TO counter.
    START-OF-SELECTION.
      CREATE OBJECT cnt.
      CALL METHOD counter=>set EXPORTING set_value = number.
    I THOUGHT WE CAN DEFINE CONSTRUCTOR METHOD OUTSIDE CLASS IMPLEMENTATION AS IN JAVA. But when I do that I get an error, method can be implemented only withing class. Why?

    Hello Rajesh
    I do not fully understand what you mean by "I THOUGHT WE CAN DEFINE CONSTRUCTOR METHOD OUTSIDE CLASS IMPLEMENTATION AS IN JAVA". However, if you mean that we can create an object without having an explicit CONSTRUCTOR method defined then this is possible in ABAP like in Java (see coding below).
    Regards
      Uwe
    REPORT ztush.
    *       CLASS counter DEFINITION
    CLASS counter DEFINITION.
      PUBLIC SECTION.
    *METHODS CONSTRUCTOR.
        CLASS-METHODS: set IMPORTING value(set_value) TYPE i,
        increment,
        get EXPORTING value(get_value) TYPE i.
      PRIVATE SECTION.
        CLASS-DATA count TYPE i.
    * NO explicit constructor
    *METHOD CONSTRUCTOR.
    *WRITE:/ 'I AM CONSTRUCTOR DUDE'.
    *ENDMETHOD.
    ENDCLASS.                    "counter DEFINITION
    *       CLASS counter IMPLEMENTATION
    CLASS counter IMPLEMENTATION.
      METHOD set.
        count = set_value.
      ENDMETHOD.                    "set
      METHOD get.
      ENDMETHOD.                    "get
      METHOD increment.
      ENDMETHOD.                    "increment
    ENDCLASS.                    "counter IMPLEMENTATION
    DATA cnt TYPE REF TO counter.
    START-OF-SELECTION.
    * Implicit constructor is called
      CREATE OBJECT cnt.
      CALL METHOD counter=>set
        EXPORTING
          set_value = 5.
    END-OF-SELECTION.

  • A java List that implements the Stream interface?

    Hello,
    I just took some time to start looking into the java-8 buzz about streams and lambdas.
    And have a couple of questions...
    The first thing that surprised me is that you cannot apply the streams operations,
    like .map(), .filter() directly on a java.util.List.
    First question:
    Is there a technical reason why the java.util.List interface was not extended with
    default-implementations of these streams operations? (I guess there is...?)
    Googling a bit, I see lots of examples of people coding along the pattern of:
        List<String> list = someExpression;
        List<String> anotherList = list.stream().map(x -> f(x)).collect(Collectors.toList());
    which becomes very clumsy, if you have a lot of these stream-operations in your code.
    Since .stream() and .collect() are completely irrelevant to what you want to express,
    you would rather like to say:
        List<String> list = someExpression;
        List<String> anotherList = list.map(x -> f(x));
    What I first did as a workaround, was to implement (see code below)
    a utility interface FList, and a utility class FArrayList (extending ArrayList with .map() and .filter()).
    (The "F" prefixes stand for "functional")
    Using these utilities, you now have two options to create less clumsy code:
        List<String> list = someExpression;
        List<String> anotherList = FList.map(list, x -> f(x));
        List<String> thirdList = FList.filter(list, somePredicate);
    or better:
        FList<String> list = new FArrayList<String>(someExpression);
        FList<String> anotherList = list.map(x -> someFunction(x));
        FList<String> thirdList = list.filter(somePredicate);
    My second question:
    What I would really like to do is to have FArrayList implement the
      java.util.stream.Stream interface, to fully support the java-8 functional model.
    Since that involves implementing some 40 different methods, I would just like to know,
    if you know somebody has already done this kind of work, and the code is
    available somewhere as a public jar-file or open-source?
        public interface FList<T> extends List<T> {
            public static <A, B> List<B> map(List<A> list, Function<A, B> f) {
                return list.stream().map(f).collect(Collectors.toList());
            public static <A> List<A> filter(List<A> list, Predicate<A> f) {
                return list.stream().filter(f).collect(Collectors.toList());
            default <R> FList<R> map(Function<T, R> f) {
                FList<R> result = new FArrayList<R>();
                for (T item : this) {
                    result.add(f.apply(item));
                return result;
            default FList<T> filter(Predicate<T> p) {
                FList<T> result = new FArrayList<T>();
                for (T item : this) {
                    if (p.test(item)) {
                        result.add(item);
                return result;
        public class FArrayList<T> extends ArrayList<T> implements List<T>, FList<T> {
            private static final long serialVersionUID = 1L;
            public FArrayList() {
                super();
            public FArrayList(List<T> list) {
                super();
                this.addAll(list);

    I believe SSH and telnet are used for interactive command line sessions, don't know how you want to use them in a program.

  • Deleting complex object in Java list (for implementation on WSDL)

    I am following those three tutorials and I have completed it with success.
    ( http://oracleadfhowto.blogspot.in/2013/03/create-simple-web-service-using-oracle.html )
    ( http://oracleadfhowto.blogspot.in/2013/03/consuming-web-service-using-web-service.html )
    ( http://oracleadfmobile.blogspot.in/2013/03/consuming-soap-web-service-in-adf.html )
    But then, as author haven't implemented removeCountries method I tried to create it.
    What I did initially was to just add to class Countries this method:
      public boolean removeCountry(Country country) {
      return countries.remove(country);
    But although compiler wasn't complaining it didn't work. Actually it worked last night (before reboot) but not today.
    Must be some SOAP iterator/bindig thing or whatever. Or I thought  that it worked but in fact it didn't.
    Here are original classes:
    public class Country {
        String CountryId;
        String CountryName;
        public Country() {
            super();
        public Country( String id, String name ) {
            super();
            this.CountryId = id;
            this.CountryName = name;
        public void setCountryId(String CountryId) {
            this.CountryId = CountryId;
        public String getCountryId() {
            return CountryId;
        public void setCountryName(String CountryName) {
            this.CountryName = CountryName;
        public String getCountryName() {
            return CountryName;
    public class Countries {   
        List<Country> countries = new ArrayList<Country>();
        public Countries() {
            super();
        public void setCountries(List<Country> countries) {
            this.countries = countries;
        public List<Country> getCountries() {
            if ( countries.size() == 0 ) {
                countries.add( new Country("IT","ITALY"));
                countries.add( new Country("IN","INDIA"));
                countries.add( new Country("US","UNITED STATES"));
            return countries;
        public boolean addCountry( Country country ) {
            return countries.add( country );
      // I added this
      public boolean removeCountry( Country country ) {
            return countries.remove( country );
    Then I decided to write (for a start) just plain Java classes and now it looks like below shown code.
    It works in IDE, not yet implemented on weblogic server. I hope it would work.
    package client;
    public class Country {
      String CountryId;
      String CountryName;
      public Country() {
      super();
      public Country(String id, String name) {
      super();
      this.CountryId = id;
      this.CountryName = name;
      public void setCountryId(String CountryId) {
      this.CountryId = CountryId;
      public String getCountryId() {
      return CountryId;
      public void setCountryName(String CountryName) {
      this.CountryName = CountryName;
      public String getCountryName() {
      return CountryName;
    package client;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    public class Countries {
      List<Country> countries = new ArrayList<Country>();
      public Countries() {
      super();
      public void setCountries(List<Country> countries) {
      this.countries = countries;
      public List<Country> getCountries() {
      if (countries.size() == 0) {
      countries.add(new Country("IT", "ITALY"));
      countries.add(new Country("IN", "INDIA"));
      countries.add(new Country("US", "UNITED STATES"));
      return countries;
      public boolean addCountry(Country country) {
      return countries.add(country);
      // This left unused
      public boolean removeCountry(Country country) {
      return countries.remove(country);
      // I added this - what would be more elegant or smarter way to do this?
      public void removeCountry(String CountryId, String countryName) {
      Iterator<Country> iterator = countries.iterator();
      while (iterator.hasNext()) {
      Country value = iterator.next();
      if (CountryId.equals(value.CountryId) || countryName.equals(value.CountryName)) {
      iterator.remove();
      break;
    This class is just for test it won't go on server (JDeveloper integrated web logic server)
    package client;
    public class UserInterface {
      public static void main(String[] args) {
      String CountryId = "";
      String CountryName = "";
      CountryName = "ENGLAND";
      Countries co = new Countries();
      co.getCountries();
      for (int i = 0; i < co.countries.size(); i++) {
      System.out.print(co.getCountries().get(i).getCountryId());
      System.out.print(" - ");
      System.out.println(co.getCountries().get(i).getCountryName());
      System.out.println("-------------------------");
      // Add some countries
      co.countries.add(new Country("DE", "GERMANY"));
      co.countries.add(new Country("EN", "ENGLAND"));
      for (int i = 0; i < co.countries.size(); i++) {
      System.out.print(co.getCountries().get(i).getCountryId());
      System.out.print(" - ");
      System.out.println(co.getCountries().get(i).getCountryName());
      System.out.println("-------------------------");
      // Remove some countries, this works but can't use this (index)
      // co.countries.remove(0); <--- there should be some index instead of 0
      // I need to set properties
      CountryId = "DE";
      CountryName = "";
      // Then remove country
      co.removeCountry(CountryId, CountryName);
      CountryId = "";
      CountryName = "ENGLAND";
      // Then remove country
      co.removeCountry(CountryId, CountryName);
      // Is there any way to remove object directly? Parameters should be set by web service iterator.
      // co.countries.remove(o);
      // co.removeCountry(country)
      for (int i = 0; i < co.countries.size(); i++) {
      System.out.print(co.getCountries().get(i).getCountryId());
      System.out.print(" - ");
      System.out.println(co.getCountries().get(i).getCountryName());
    I would like to avoid my own iterator as JDeveloper can generate automatically iterators for webservices, but if I can't get it that way, what would be better way to write above mentioned iterator in removeCountry method?
    Is there any way to remove object directly with something like this:
    co.countries.remove(o);
    co.removeCountry(country)
    using method
      // This left unused
      public boolean removeCountry(Country country) {
      return countries.remove(country);
    from class Countries?
    Parameters should be set by web service iterator.

    Secure Sockets - http://java.sun.com/j2se/1.4.2/docs/guide/security/jsse/JSSERefGuide.html
    OR
    an HttpsURLConnection is returned from URL.openConnection() when the URL is an HTTPS URL.

  • Concrete classes implement abstract class and implements the interface

    I have one query..
    In java collection framework, concrete classes extend the abstract classes and implement the interface. What is the reason behind extending the class and implementing the interface when the abstract class actually claims to implement that interface?
    For example :
    Class Vector extends AbstractList and implements List ,....
    But the abstract class AbstractList implements List.. So the class Vector need not explicitly implement interface List.
    So, what is the reason behind this explicit definition...?
    If anybody knows please let me know..
    Thanx
    Rajendra.

    Why do you post this question again? You already asked this once in another thread and it has been extensively debated in that thread: http://forum.java.sun.com/thread.jsp?forum=31&thread=347682

Maybe you are looking for