The arrays class question

consider the code below
int[] list = {2, 4, 7, 10};
java.util.Arrays.fill(list, 7);
java.util.Arrarys.fill(list, 1, 3, 8);
System.out.print(java,util.Arrays.equals(list, list));i understand line 2, it gonna fill 7 into the array,so the output would be Line 2: list is {7, 7, 7, 7}
my question is line 3, how come the output would be {7, 8, 8,7} what does 1 and 3 represent in a arrary?
the line 4 output would be {7, 8,8,7} again why?
Thank you guys whoever is gonna take to respond me questions

zerogpm wrote:
but which 2 lists were comparing ? since i have list list with the same name1) You're not comparing lists, you're comparing arrays.
2) You're comparing a single array with itself.
3) Objects, including arrays, do not have names. Classes, variables, and methods have names. Objects do not.

Similar Messages

  • Why can't the Web console in FF9.01 not see extensions I've added to the Array class (object)?

    I've added a number of new methods to the Array object in Javascript. My scripts see them fine, but the Web console reports them as 'undefined'. Apparently the console cannot see my changes. Why is that?

    Not the same. It should be like the orange indicator for an imported clip in the camera import window. It's really quite sophisticated in iMovie. When you switch projects the orange line changes to reflect what's in the open project so a clip might have the orange indicator when one project is open in the timeline, and not when another project is open. It's a really useful tool, because it even shows what parts of a clip have been used in the open project.

  • Extending Array class, get Error #1069: Property 0 not found with indexOf call

    I'm using inheritance to extend the Array class to create a Paths class that moves Sprites/MovieClips around on the screen. I'm getting an odd error on a call to indexOf. Here's the error:
    ReferenceError: Error #1069: Property 0 not found on Paths and there is no default value.
        at Array$/_indexOf()
        at Array/http://adobe.com/AS3/2006/builtin::indexOf()
        at Paths/Next()[D:\Stephen\Documents\Flash\TossGame\TossGameFirstPerson\Paths.as:40]
    Here's the relevant code in the Paths class:
        public class Paths extends Array
            private var cCurrentPath:Path;
            public function Next():Path
                var lArray:Array = this;
                var lNextIndex:int = indexOf(cCurrentPath) + 1;
                if (lNextIndex == length) lNextIndex = 0;
                var lPath:Path = lArray[lNextIndex];
                return lPath;
        } // class
    I get the error at the highlighted line. cCurrentPath is populated with a Path object which is the object located at position 0 of the this object (Paths). I've tried the following variants of the Next() function:
    public function Next():Path
         var lArray:Array = this;
          var lNextIndex:int = lArray.indexOf(cCurrentPath) + 1;
          if (lNextIndex == lArray.length) lNextIndex = 0;
          var lPath:Path = lArray[lNextIndex];
          return lPath;
    public function Next():Path
         var lArray:Array = this;
          var lNextIndex:int = this.indexOf(cCurrentPath) + 1;
          if (lNextIndex == this.length) lNextIndex = 0;
          var lPath:Path = lArray[lNextIndex];
          return lPath;
    public function Next():Path
         var lArray:Array = this;
          var lNextIndex:int = super.indexOf(cCurrentPath) + 1;
          if (lNextIndex == super.length) lNextIndex = 0;
          var lPath:Path = lArray[lNextIndex];
          return lPath;
    Same error happens whichever I try. Anyone got any ideas?
    Stephen
    Flash Pro CS3 (Version 9.0)

    Mark your class dynamic.
    public dynamic class Paths extends Array

  • [Question]how to count the occurance of numbers inside the array

    im just practicing my java skill but i cant get my program work can you give me guys some idea on how to determine a number that occured more than 1 inside the array e.g i have 10 elements and inside of my offset i have
    1,2,5,4,5,6,5,8,9,5
    and what im planning to do is count the occurances of the number who occures more than 1 and for that 5 occur 3 times how my program can know that i use for loop but cant figure out how to filter the occurances of numbers inside
    my offset
    thank's

    Encephalopathic you said put - 1 instead i did - 2
    public class sample
       public static void main(String args[])
          int num[] = {2,2,2};
          int index1, count = 0, find = 0;
          for(index1 = 0; index1 < num.length - 2; index1++)
             for(int index2 = 0; index2 < num.length; index2++)
                if(num[index2]==num[index1])
                  find = num[index2];
                  count++;
             System.out.println("i found " + find + " " + count + " same number inside your offset");
    }output is:
    i found 2 3 same number inside your offset
    but another question is what if i want my program to tell the other number that occur 1 time
    like this:
    i found 1 2 same number inside your offset
    i found 2 0 same number inside your offset
    i found 1 2 same number inside your offset

  • Where is the getString() implementation for RS and Object class question

    Dear all,
    I had these two questions ringing since a long time.
    1)ResultSet is an interface.
    In my jdbc code I have generally written rs.getString() and rs.getInt etc.. without giving a second thought as to where exactly is this getter implemented !
    I have RTF API .. without too much help.
    Could some one kindly explain Where is the implementation of the getString method ?
    2) Could you please tell why the Wait() Notify() and NotifyAll methods have been implemented in the Object class ? What was the need to define em in the Object class ?
    Thanks in advance for your time spent on this.
    Rgds

    Sarvananda wrote:
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    Rgds
    >
    In the MySQL driver for example it's implemented in com.mysql.jdbc.ResultSet Right. Now it makes sense to me. Every single db that gives me a driver will have their specific implementation for the interface methods of ResultSet.
    >
    why do you need that?
    ..Thats a design decision
    One of my friends asked me this and I was caught unawares. Any ideas on what factors could have made this design decision ?
    A desire to not have to couple your code to a particular database and JDBC driver. It's a classic example of the abstract factory pattern

  • Forwarding the array of object to servlet class

    Hi
    i am new to this j2ee.So please cooperate with me.
    i am having an array of objects in a jsp page.
    Each object represent a option which could be seelected through radio button.
    Now i want to send one selected object,corresponding to selected radio button to my servlet ManageUser.
    how can i do that.can any one help me please.
    i have been trying like this but i guess it is not correct .
    <%--   
    --%>   
    <%@page contentType="text/html" pageEncoding="UTF-8"%>    
    <%@page import="abc.javabean.EmpJavaBean"%>  
    <!--importing pages(classes) to implement request response  -->  
    <%@page import="javax.servlet.ServletException"%>  
    <%@page import="javax.servlet.http.HttpServlet"%>  
    <%@page import="javax.servlet.http.*"%>  
    <%@page import="javax.servlet.RequestDispatcher"%>  
    <%@page import="java.util.*"%>  
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
       "http://www.w3.org/TR/html4/loose.dtd">    
    <html>  
        <head>  
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
            <title>JSP Page</title>  
            <script type="text/javascript">  
                //function for selecting the radio  
                function validateRadio(fetchedArrayObject)  
                    alert("hi");  
                    var thisone=-1;  
                    for(i=0;i<document.searchedEmpForm.radioGroup.length;i++)  
                            if(searchedEmpForm.radioGroup.checked==true)
    thisone=i;
    alert(thisone);
    var name=fetchedArrayObject[i].getEmpName();
    alert(name);
    session.setAttribute("fetchedArrayObject[i]",fetchedArrayObject[i]);
    if(thisone==-1)
    alert("you must select a radio Button");
    return false;
    return true;
    </script>
    </head>
    <body bgcolor="#8db6cd">
    <!--retreaving the array values from the servlet -->
    <%
    //int a;
    EmpJavaBean fetchedArrayObject[]=new EmpJavaBean[4];
    fetchedArrayObject=(EmpJavaBean[])request.getAttribute("substituteArray");
    //a=fetchedArrayObject[0].getEmpNumber();
    %>
    <h3>ur new no is <%=fetchedArrayObject[0].getEmpNumber()%></h3><br>
    <form name="searchedEmpForm" action="/Precize/ManageUser" onsubmit="return validateRadio(fetchedArrayObject)">
    <br></br>
    <h2 align="center">Your Searched Result Is Here</h2>
    <br></br>
    <table border="1" align="center">
    <thead>
    <tr>
    <th> </th>
    <th> <input type="button" value="Emp#" name="searchedPageEmpNumb"> </th>
    <th> <input type="button" value="Name" name="searchedPageEmpName"> </th>
    <th> <input type="button" value="Priv" name="searchedPageEmpPriv"> </th>
    <th> <input type="button" value="Role" name="searchedPageEmpRole"> </th>
    <th> <input type="button" value="Start Date" name="searchedPageEmpStartDate"> </th>
    <th> <input type="button" value="End Date" name="searchedPageEmpEndDate"> </th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td><input type="radio" name="radioGroup" value="r11" ></td>
    <td><%=fetchedArrayObject[0].getEmpNumber()%></td>
    <td><%=fetchedArrayObject[0].getEmpName()%></td>
    <td><%=fetchedArrayObject[0].getEmpPrivilege() %></td>
    <td><%=fetchedArrayObject[0].getEmpRole()%></td>
    <td><%=fetchedArrayObject[0].getEmpStartdate()%></td>
    <td><%=fetchedArrayObject[0].getEmpEndDate() %></td>
    </tr>
    </tbody>
    </table>
    <br><center><input type="submit" value="Update" name="updateButton" ></center>
    <h3 align="center">Select the Employee To be Updated/deleted</h3>
    </form>
    </body>
    </html>
    please suggest me the answer.
    regards
    thanx                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I think you need to learn the difference between "java" and "javascript"
    calling session.setAttribute from a javascript function will not have the effect that you desire.
    If you give all radio buttons the same "name", then request.getParameter("radioGroup") should tell you the value of the selected one.

  • Reflection question: Creating dynamic array classes

    I'm trying to create a String[].class dynamically by passing into a method the value "String[]" and then returning the Class, but I can't get my head around creating an array version.
    e.g.
    public Class classFromName(String className)
    return Class.forName(className);
    but it fails on arrays passed in. Fine for "String", but not "String[]" or "String[][]".
    Is this possible?
    Thanks
    Mark Fisher ([email protected])

    I couldn't get just "String" to work.
    But remember that you usually write just "String" in source code because there's an implicit import java.lang.* statement at the beginning of your Java source code. That means that "java.lang.String" is the full name of the class. Imports apply onto to source code and are not "remembered" after the compilation process is finished.
    If you want an array of Strings, the JVM name for that class is "[Ljava.lang.String;". I think there's also a way of getting the class object for array types in the reflection classes... I'll let you look for that in the API docs.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Can anyone help me change fonts and size on my page? I don't understand the class questions?

    Can anyone help me change fonts and size on my page? I don't understand the class questions? All I want to do is change the font and size of a table or div.
    http://www.allgearinc.com/AG12SSWL-Swift.htm -One problem page

    If you want to change the fonts of the entire page then this code will do the trick:
    body {
        font-size: 16pt;
        color: silver;
         font-family: whatever, goes, here;
    If you want to change the fonts of ALL tables on a page then the code is something like this:
    table {
        font-size: 20pt;
        font-family: "Courier New", Courier, monospace;
        font-style: italic;
        font-weight: bold;
    what exactly do you want to change?  Can you be a bit specific so that Ben or Ken can give you the exact code and tell you about the short-hand method to write the code in one line.
    Have you bought a book on CSS yet?  If not, it is a good idea to get one as a reference.  Eric Meyer writes good books on CSS.

  • A question about the getProperty method defined in the Security class

    Hello Everyone!
    I would like to ask a question about the getProperty method defined in the
    Security class.
    public static String getProperty(String key) Do you know how can I exract the list of all possible keys?.
    Thanks in advance,

    I found the answer, in fact the keys are defined in the java.security file.

  • Question about the property of the nested class.

    "Nested classes may be declared static. In this case, the nested class has no reference to an enclosing instance"
    Can any one demonstrate the above through an code example?? thanks

    thanks jverd.
    Then why dont you answer my other thread??You have several threads. I've said what I have tosay in all the ones that I know about, am interested
    in, and have the time to answer. Last one I lookedat, you were in Monica's very capable hands, so I had
    nothing to add.
    Thanks!I may not be the sharpest knife in the drawer, but I know better than to piss of her what's gonna administer the dread Blueberry Pie Torture.

  • Question about the String class

    Did I understood the JLS/Javadoc properly if I say that the String class has got an internal pool of String objects (therefore I expect this pool to be stored in some sort of static variable)?
    Looking at the intern() method in the String class, this is declared as native, which make me think the whole pooling thing is managed internally by the JVM.
    Does this mean that, if there is only a String class per JVM and String literals (or better Strings that are values of constant expressions) are pooled in the String class, the more String constants are around the bigger the String class object becomes?

    Did I understood the JLS/Javadoc properly if I say
    that the String class has got an internal pool of
    String objects (therefore I expect this pool to be
    stored in some sort of static variable)?Yes.
    Looking at the intern() method in the String class,
    this is declared as native, which make me think the
    whole pooling thing is managed internally by the JVM.The intern() method is implemented in some programming language. If you happen to have a Java runtime where it is written as a native method, it is probably implemented in C or C++. Not a terribly important detail.
    Does this mean that, if there is only a String class
    per JVM and String literals (or better Strings that
    are values of constant expressions) are pooled in the
    String class, the more String constants are around
    the bigger the String class object becomes?The String.class object (of type java.lang.Class) as such doesn't "grow", but some memory structure somewhere will contain interned String literals. Probably a hash table of some sort. Yes indeed: if you have String literals in your program, those literals are stored in the computer's memory during runtime so that they can be accessed by the executable program code.

  • The HttpServlet Class. A question for all please

    Hello there,
    When we write our Servlets,we extend the HttpServlet class.
    This class is an abstract class having the doGet() and doPost()
    methods which we normally override for our custom functionality.
    We cannot instantiate this class as this is abstract.
    Why couldnt this be defined as an Interface then?
    This could then have the same doGet() and doPost() methods which
    we could then implement in our class.
    Can any one explain to me this difference or am I missing anything
    here.?
    Wouldnt defining the HttpServlet class as an Interface be a viable
    solution?
    Regards
    Ajay

    "An interface cannot implement any methods, whereas an abstract class can"
    HttpServlet extends GenericServlet and has methods so it can not be an interface.

  • Can not filter the data with the extended class

    Hi,
    I have a quick question about PortableObject format. I have created a class which extends PortableObject interface and implemented serializer methods as well. I have updated it in the pof-config.xml file as well. If I insert the objects of this type of object in the cache, they get inserted properly and I can filter the values based on the getters defined in the class. Everything works fine here.
    Now, I am trying to extend the existing class that I have. We have our custom API which we have built for our domain objects. I need to store these objects in the cache. So, naturally I need to implement PortableObject interface to do that. So, instead of creating a new class with new set of getters and setters and local fields, I am extending our domain class to create a new class which implements PortableObject interface. Instead of defining the local fields and getters and setters i am reusing the ones provided by my existing class. Now, I can insert the objects of the new class to the cache. But I can not filter the values for the objects of this new class.
    Let me show you what exactly I am trying to achieve by giving a small example:
    Domain Class:
    class Person
    private String person_name;
    *public String getPerson_name() {return person_name;}*
    *public String setPerson_name(person_name) {this.person_name = person_name;}*
    The new class implementing PortableObject interface:
    class ExtPerson extends Person implements PortableObject
    public static final PERSON_NAME = 0;
    *public void readExternal(PofReader reader) throws IOException{*
    setPerson_name(reader.readString(PERSON_NAME));
    *public void writeExternal(PofWriter writer) throws IOException{*
    writer.writeString(PERSON_NAME, getPerson_name());
    *// And HashCode, Equals and ToString methods, all implemented using the getter from the Person class*
    So, if I create a new class ExtPerson without extending the Person class and write all the methods, store the objects in the cache and perform the following query, I get the size printed
    System.out.println((cache.entrySet(new EqualsFilter("getPerson_name","ABC"))).size());
    But if I use the extended class and insert the values into the cache and if I use the same query to filter, I get 0 printed on the console.
    System.out.println((cache.entrySet(new EqualsFilter("getPerson_name","ABC"))).size());
    So, can anyone tell what exactly is causing this?
    Thanks!

    Well, just a quick question. It seems that I can not get ContainsAnyFilter or ContainsAllFilter working.
    EqualsFilter is actually working properly.
    I am preparing a Set of Strings and passing it to ContainsAnyFilter or ContainsAllFilter and it is returning me 0 records.
    E.g.:
    Set<String> setStr = new HashSet<String>();
    setStr.add("ABC");
    setStr.add("DEF");
    System.out.println((cache2.entrySet(new ContainsAnyFilter("getPerson_name", setStr))).size());
    I get 0 in my output
    If I try this:
    System.out.println((cache.entrySet(new EqualsFilter("getPerson_name","ABC"))).size());
    System.out.println((cache.entrySet(new EqualsFilter("getPerson_name","DEF"))).size());
    I get 1 for each of the query.
    If I club all these EqualsFilter in a Filter[] array and create an AnyFilter or AllFilter and pass it to the query, it works fine.
    List<Object> lst = new ArrayList<Object>();
              lst.add("ABC");
              lst.add("DEF");
    Filter[] filter = new Filter[lst.size()];
         for(int i=0;i<lst.size();i++)
              filter[i] = new EqualsFilter("getPerson_name",lst.get(i).toString());
    AnyFilter fil = new AnyFilter(filter);
    System.out.println((cache4.entrySet(fil)).size());
    I get the desired result here, which is 2.
    Am I missing something here?

  • Java sorting the array of objects

    Hi ,
    I have a question on sorting objects in java.
    I have a java interface some thing like :
    public classmyObj extends Nullable
        private int objId;
        private Datemydate;
        public int getObjID();
        public Date getmyDate();
        public int getISecondD();
      }I need to create the array of the objects of this class that are sorted on the ObjID:
    classmyObj[] collectionObjects
    I need to pass this collectionObjects to another function.
    Now how should I sort these objects based on the ObjID on collection?
    Please help with this!
    Thanks

    neeto wrote:
    Hi ,
    I have a question on sorting objects in java.
    I have a java interface some thing like :You mean class?
    >
    public classmyObj extends Nullable
    private int objId;
    private Datemydate;
    public int getObjID();
    public Date getmyDate();
    public int getISecondD();
    }I need to create the array of the objects of this class that are sorted on the ObjID:
    classmyObj[] collectionObjects
    I need to pass this collectionObjects to another function.
    Now how should I sort these objects based on the ObjID on collection?Create a comparator and use it in a call to Collections.sort (or Arrays.sort if you have an array)

  • Some subclassing array creation question

    i)     Declare a class Customer which contains name, id , payment, and status. [5m]     
    ii)     Create a class called Shop that contains a one dimensional arrays� reference of type Customer Mall which      stores up to 45 Customer information.     [2m]
    Above are the question. I just want to know should the Shop class extends the Customer class or is it unecessary.

    I dont think you should use the extends keyword.
    Ask yourself which of these statements makes sense:
    A Customer is-a Shop.. (I dont think so)
    A Shop is-a Customer.. (That doesn't make sense either)
    A Shop has-a Customer... (now that sounds right)
    Given that I would have a instance variable of type Customer[] within the Shop class.
    Use composition instead of inheritance.
    I hope this helps..
    J

Maybe you are looking for