Import the classes in the package java.util
I haven't taken a class in two years so I have ideas but am unsure of myself, and I most likely am way off base, but is this how you import the classes in the package java.util
import java.util.*;
I would appreciate anyone's help. I have a lot of questions.
Thanks,
rp
My assignment is below so that you will know exactly what I am asking. I am being asked to create an instance of LinkedList. I know that this is a part of the java.util. So when you create an instance of LinkedList would that be similar to instance variables? or am I misunderstanding something. I have several ideas, so I will start with the first one.
LinkList();
I really appreciate your taking the time to answer my questions to help me to rebuild my confidence in doing this.
Thanks,
// 2. import the classes in the package java.util
public class MyProgram
public static void main(String [] args)
// 3. Create an instance of LinkedList
// 4. add 5 entries to the list so that it contains
// Ann, Bart, Carl, Dirk, Zak
// 5. display the list on one line using a loop and ADT list methods
System.out.println("\n\n3. ");
// 6. display the list using one println
System.out.println("\n\n4. ");
// 7. create a ListIterator object for the list
// 8. display the list on one line using the iterator
System.out.println("\n\n6. ");
// 9. restore the iterator to the first item in the list
// 10. retrieve and display the first item in the iteration,
// then advance the iterator to the next item
System.out.println("\n\n8. ");
// 11. advance the iterator to the end of the list without displaying anything;
// do not use the length of the list
// 12. display the last item in the list
System.out.println("\n\n10. ");
// 13. move back to the beginning of the list without displaying anything;
// do not use the length of the list
// 14. display the first item in the list
System.out.println("\n\n12. ");
// 15. advance the iterator to the end of the list without displaying anything;
// 16. advance the iterator - what happens?
System.out.println("\n\n14. ");
// 17. advance the iterator within a try block; catch the exception, display a message,,
// and set the iterator back to the beginning of the list.
System.out.println("\n\n15. ");
// 18. what does nextIndex and previousIndex return?
System.out.println("\n\n16. ");
// 19. move the iterator to the third item in the list; if you were to
// execute next(), the third item would be returned and the iterator
// would advance to the 4th item.
System.out.println("\n\n17. ");
// 20. add the string "New" to the list; where is it inserted relative to
// the current item in the iteration?
System.out.println("\n\n18. ");
// 21. remove the current item; what happens?
System.out.println("\n\n19. ");
// 22. display the current item in the list without advancing the iteration
// in 2 ways, as follows:
// 22A - using only iterator methods
System.out.println("\n\n20A. ");
// 22B using an iterator method and list methods
System.out.println("\n\n20B. ");
// 23. advance the iterator and remove the current item; which one is removed?
System.out.println("\n\n21. ");
// 24. move the iterator back and remove the current item; which one is removed?
System.out.println("\n\n22. ");
// 25. move the iterator to the first item in the list and change it to "First"
System.out.println("\n\n23. ");
} // end main
} // end MyProgram
Similar Messages
-
How to import a class from a package at the same level
Hello friends,
i have a class as Plaf.java
as
package org.vaibhav.swing.plaf;
import java.awt.*;
import javax.swing.*;
public class Plaf {
other code
}as you see, this is in org.vaibhav.swing.plaf package.
I have one more class as
package org.vaibhav.swing.frames;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StartFrame extends JFrame implements ActionListener {
other code
}and this class is in package org.vaibhav.swing.frames
Please hlp me how to use the class Plaf in StartFrame.java. Rather what import statement should i use in StartFrame.java.
please help.
thank you
Message was edited by:
vaibhavpinglebut it then gives me this error
StartFrame.java:11: package org.vaibhav.swing.plaf
does not exist
import org.vaibhav.swing.plaf.*;
Have you first compiled Plaf.java and saved it in this directory strucuture
/org/vaibhav/swing/plaf/
And also have you set your classpath to the parent directory of org folder.
Message was edited by:
qUesT_foR_knOwLeDge -
How to convert the class in the one package to same class in the other pack
How to convert the class in the one package to same class in the other package
example:
BeanDTO.java
package cho3.hello.bean;
public class BeanDTO {
private String name;
private int age;
* @return
public int getAge() {
return age;
* @return
public String getName() {
return name;
* @param i
public void setAge(int i) {
age = i;
* @param string
public void setName(String string) {
name = string;
BeanDTO.java in other package
package ch03.hello;
public class BeanDTO {
private String name;
private int age;
* @return
public int getAge() {
return age;
* @return
public String getName() {
return name;
* @param i
public void setAge(int i) {
age = i;
* @param string
public void setName(String string) {
name = string;
My converter lass lokks like
public class BeanUtilTest {
public static void main(String[] args) {
try
ch03.hello.BeanDTO bean=new ch03.hello.BeanDTO();
bean.setAge(10);
bean.setName("mahesh");
cho3.hello.bean.BeanDTO beanDto=new cho3.hello.bean.BeanDTO();
ClassConverter classconv=new ClassConverter();
//classconv.
System.out.println("hi "+beanDto.getClass().toString());
System.out.println("hi helli "+bean.toString()+" "+bean.getAge()+" "+bean.getName()+" "+bean.getClass());
Object b=classconv.convert(beanDto.getClass(),(Object)bean);
System.out.println(b.toString());
beanDto= (cho3.hello.bean.BeanDTO)b;
System.out.println(" "+beanDto.getAge()+" "+beanDto.getName() );
}catch(Exception e)
e.printStackTrace();
But its giving class cast exception. Please help on this..Do you mean "two different layers" as in separate JVMs or "two different layers" as in functional areas running within the same JVM.
In either case, if the first class is actually semantically and functionally the same as the second (and they are always intended to be the same) then import and and use the first class in place of the second. That's beyond any question of how to get the data of the first into the second if and when you need to.
Once you make the breakthrough and use one class instead of two I'd guess that almost solves your problem. But if you want to describe your architecture a little that would help others pin down want you're trying to do. -
Accessing Class not in the package by the Class in the Package.
Hi All,
I am using window my java application are located at
c:\javaProg\completeReferance\......
my Class path is set to c:\....
Iexecute java application using
java javaProg.completeReferance.MyProgramThe problem is when I wanted to use some other class which is not in any package I get the following error.(say class Car).
C:\Users\pravin>javac c:\javaProg\completeReferance\SystemDemo2.java
c:\javaProg\completeReferance\SystemDemo2.java:7: cannot find symbol
symbol : class Car
location: class javaProg.completeReferance.SystemDemo2
Car object = new Car();
^
c:\javaProg\completeReferance\SystemDemo2.java:7: cannot find symbol
symbol : class Car
location: class javaProg.completeReferance.SystemDemo2
Car object = new Car();
^
2 errorsThis is my program ...package javaProg.completeReferance;
public class SystemDemo2
public static void main(String [] args)
Car object = new Car();
}Where should it place the class file for Car class.Can some one explains who to make the class from one package compitable with classes in default package or any other package.I hope this problem may be faced by lots of newbies.
Appreciate your concern!
Message was edited by:
confused_in_javaThere's nothing wrong with it per se... but it has a
number of pitfalls. Basically it's a hell of a lot
more likely to go wring at runtime than the good ole
"just put the class in a package and import the
sucker properly" solution.Alredy implemented this now.
That's what makes me shudder to see it in the
(forgive me) shakey hands of a newbie... it's a bit
like watching a tree year old trying to open a box of
matches... if you've got any brains you push the
rubber ducky in his hands and quietly secrete the
matches in the cupboard above the fridge... and get
yourself another beer whilste you're there.
Christians don't drink on Sunday. So there's more for
me.Thanks I wil remember this.
I am about to put a new Thread I thought insted so putting a new thread I will ask it here.
This Question is a bit wiered so please excuse me if you think this is foolish.
I was just wonder that if we can put our package, which include classes offcourse at some web location, then this will be available to us from anywhere and can be shared all accross.
So I am tring to dumb the package in a jarfile and place it at my webspace http://pravin.biz.ly/ how ever somehow i have problem doing it can any one help.
Regards!!
Pravin Dubey.
Message was edited by:
confused_in_java -
Import individual classes or entire package?
Hi All,
This is just a general curiosity question but I was wondering what the best way is to import mulitple classes from the same package. i.e. is it better to do something like this:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;or this:
import java.awt.*;Is the compiler smart enough to only import the needed classes as would be the case in 'import java.awt.*;'?This document had some pretty good reason not to use the .* import:
http://wwws.sun.com/software/sundev/whitepapers/java-style.pdf
- The most important reason is that someone can later add a new unexpected class file to the same package
that you are importing. This new class can conflict with a type you are using from another package,
thereby turning a previously correct program into an incorrect one without touching the program
itself.
- Explicit class imports clearly convey to a reader the exact classes that are being used (and which classes
are not being used).
- Explicit class imports provide better compile performance. While type-import-on-demand declarations
are convenient for the programmer and save a little bit of time initially, this time is paid for in
increased compile time every time the file is compiled. -
Error : the class does not match the class of the persisted object
Hi I am new to Java.. I got an exception "the class does not match the class of the persisted object for cl = java.util.Vector : __SUID = -2767605614048989439, getSUID(cl) = 1".. What it implies? I got Serialized stream and Object from Web Server.. How to resolve this Exception? I nead to Deserialize this stream...
ArulPrabhu wrote:
Friend... I agree with u... Every thing Ok... I am not having the option to make change on the server side... I call a webrequest for the URI - "http://www.nseindia.com/chartdata?mkttype=N&series=EQ&symbol=RPOWER&charttype=ONLINE_STOCK".. From that i got response as Serialized Object Stream... Which is the data made available to all through their applet "Chart".. But i need it for my Custom Project.. I know the Structure of class they have serialized... Is their any chance to parce Data from that Stream..
Three words.
You are doomed.
Whatever you end up doing will not be serialization. It will be reverse engineering of a old (dead) format that could go all pear shaped on you when you least expect it. One of the worst problems in using a solution where you reverse engineer, try and guess hackery your way through a proprietary semi (or totally) undocumented format is that it is really impossible to test your code with any degree of certainty. Does your code actually work? Or does it only work because you haven't seen some totally unexpected (but legal for the format) format yet?
Get the producer to produce XML instead of "serialized" data. This is a much better route for you to go down.
If you decide to keep on your path then grab a DataInputStream and go somewhere else because you'll have to figure out the format of another languages serialized data on a place that isn't this site. -
Compile and call the class during the runtime
Hi guys,
I am struggling with a project, which allow user to modify the behavior of the program.
To do this, my Java code must be able to compile the Java code (*.java) and call the class from the code during the runtime.
Here are my code:
com.sun.tools.javac.Main javac = new com.sun.tools.javac.Main();
String[] options = new String[] {"d:\\javaExternal\\RunTimeCompilation.java"};
System.out.println(Main.compile(options));This allows me to compile the .java file into .class file. However, I can't find the way to access/use the .class file.
Do you guys have solution for this?
Thanks a lot.You will also need to investigate class unloading and proxies since presumably they can modify the file and compile it again.
Might note that in general this seldom works for business solutions. It seems like allowing the users to add their own functionality would be a good idea so the programmers don't have to keep doing it. But the reality is that then the users must become programmers. And often must be pretty good at it as well since they must not only know the programming language but also the framework too. The second problem is that it also becomes a maintenance nightmare for the real developers to upgrade the existing system. -
How to "include" the class into the calling main()
I posted yesterday and cant find the thread so apologize if its already answered. Question is, if you make a class, say Class QA, then if you call it from a file while has the main() in it, what do you include or add in this calling file that will tell it that there is a class A defined . (Main uses class A). I cant find this anuywhere- though I dont have many resources yet.
Thanks,
nsI have the class in the same folder but it says on compile"
C:\java>java GUIFrameTest
Exception in thread "main" java.lang.NoClassDefFoundError: GUIFrameTest
C:\java>here is my dir:
C:\java>dir
Volume in drive C has no label.
Volume Serial Number is 07D1-0702
Directory of C:\java
09/29/2002 09:26a <DIR> .
09/29/2002 09:26a <DIR> ..
09/29/2002 10:02a 825 GUIFrame.java
09/29/2002 10:02a 1,370 GUIFrame.class
09/30/2002 05:50a 176 GUIFrameTest.java
7 File(s) 3,036 bytes
2 Dir(s) 8,337,620,992 bytes free
C:\java>and the test class is:
public class GUIFrameTest{
public static void main(String args[]){
GUIFrame frame = new GUIFrame("GUIFrame Test");
frame.setSize(400,300);
frame.setVisible(true);
Help! -
The class of the deferred-methods return type "{0}" can not be found.
I am developing a multilingual portal application.
I have the method that changes the locale based on user's choice in the bean and the method is being referred to as below.
<af:selectOneChoice label="Select Language" autoSubmit="true"
value="#{localeBean.locale}"
valueChangeListener="localeBean.changeLocale">
<af:selectItem label="English" value="en" id="si1"/>
<af:selectItem label="French" value="fr" id="si2"/>
<af:selectItem label="Dutch" value="nl" id="si3"/>
</af:selectOneChoice>
when i try to run the application, i am getting compile time errors as below,
The class of the deferred-methods return type "{0}" can not be found.
No property editor found for the bean "javax.el.MethodExpression".
After going through the discussion forums i learned that the compilation errors can be resolved by setting the <jsp:directive.page deferredSyntaxAllowedAsLiteral="false> at the starting of the page.
Even after that i am getting the compilation error.
Any solutions, suggestions or possible approaches would be helpful as i am new to Webcenter Portal development.
Thanks,The error you get points to a problem on the page (somewhere). Switch to source mode and check the right margin if you see orange or red marks. These are pointing to problems (not all are show stoppers, but they give you hints that something is not according to the standard for jsf, jsff, jsp or jspx pages.
Have you checked that the bean is correctly defined and that it's reachable?
Start a fresh page and isolate the problem, e.g. build a selectOneChoiuce on the new page (don't copy it as you might copy the error too) and make it work on the new page. Once you have it running you can compare the solution to your not running page.
Timo -
I think the class in the packet will be useful.
But I don't konw how to use it.
Do you get me a example.
Thanks.Hi,
Issue has been resolved. I used the value of the element to determine to display it or not.
Regards,
Swapnil K. -
Cannot use winzip to unzip the zip file zipped by java.util.zip
Hi all,
I use the followcode to create a zip file, and i downlaod it and try to use winzip to unzip this file but fail. The path is correct and i got the zip file. but it just cannot unzip.
pls help
thanks alot.
Kin
int count = 0;
count = ContentDocuments.size();
for (int i = 0; i < bb; i++) {
System.out.println(filenames[i] + "");
// Create a buffer for reading the files
byte[] buf = new byte[10*1024*1024];
try {
String outFilename = MyDir + "zipfile/" + getContentID2()+".zip";
System.out.println("outFilename = " + outFilename);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
for (int i=0; i<filenames.length; i++) {
FileInputStream in = new FileInputStream(filenames);
out.putNextEntry(new ZipEntry(filenames[i]));
int len;
while ((len = in.read(buf)) != -1) {
out.write(buf, 0, len);
out.closeEntry();
in.close();
out.close();
} catch (IOException e) {
System.err.println("zipprocess " + e.getMessage());I've written a replacement zip file creator class. Not much tested but it seems to work, however I've yet to try it with the version of WINZIP that rejected my previous attempts. Oh, and the stored dates are garbage.
* ZipOutputFile.java
* Created on 25 March 2004, 13:08
package zip;
import java.io.IOException;
import java.nio.ByteBuffer;
* <p>Creates a ZIP archive in a file which WINZIP should be able to read.</p>
* <p>Unfortunately zip archives generated by the standard Java class
* {@link java.util.zip.ZipOutputStream}, while adhering to PKZIPs format specification,
* don't appear to be readable by some versions of WinZip and similar utilities. This is
* probably because they use
* a format specified for writing to a non-seakable stream, where the length and CRC of
* a file is writen to a special block following the data. Since the length of the binary
* date is unknown this makes an archive quite complicated to read, and it looks like
* WinZip hasn't bothered.</p>
* <p>All data is Deflated. Close completes the archive, flush terminates the current entry.</p>
* @see java.util.zip.ZipOutputStream
* @author Malcolm McMahon
public class ZipOutputFile extends java.io.OutputStream {
byte[] oneByte = new byte[1];
java.io.RandomAccessFile archive;
public final static short DEFLATE_METHOD = 8;
public final static short VERSION_CODE = 20;
public final static short MIN_VERSION = 10;
public final static int ENTRY_HEADER_MAGIC = 0x04034b50;
public final static int CATALOG_HEADER_MAGIC = 0x02014b50;
public final static int CATALOG_END_MAGIC = 0x06054b50;
private final static short DISC_NUMBER = 0;
ByteBuffer entryHeader = ByteBuffer.wrap(new byte[30]);
ByteBuffer entryLater = ByteBuffer.wrap(new byte[12]);
java.util.zip.CRC32 crcAcc = new java.util.zip.CRC32();
java.util.zip.Deflater def = new java.util.zip.Deflater(java.util.zip.Deflater.DEFLATED, true);
int totalCompressed;
long MSEPOCH;
byte [] deflateBuf = new byte[2048];
public static final long SECONDS_TO_DAYS = 60 * 60 * 24;
* Entry stores info about each file stored
private class Entry {
long offset; // position of header in file
byte[] name;
long crc;
int compressedSize;
int uncompressedSize;
java.util.Date date;
* Contructor also writes initial header.
* @param fileName Name under which data is stored.
* @param date Date to label the file with
* @TODO get the date stored properly
public Entry(String fileName, java.util.Date date) throws IOException {
name = fileName.getBytes();
this.date = date == null ? new java.util.Date() : date;
entryHeader.position(10);
putDate(entryHeader);
entryHeader.putShort(26, (short)name.length);
offset = archive.getFilePointer();
archive.write(entryHeader.array());
archive.write(name);
catalog.add(this);
crcAcc.reset();
totalCompressed = 0;
def.reset();
* Finish writing entry data. Save the lenghts & crc for catalog
* and go back and fill them in in the entry header.
public void close() throws IOException {
def.finish();
while(!def.finished())
deflate();
entryLater.position(0);
crc = crcAcc.getValue();
compressedSize = totalCompressed;
uncompressedSize = def.getTotalIn();
entryLater.putInt((int)crc);
entryLater.putInt(compressedSize);
entryLater.putInt(uncompressedSize);
long eof = archive.getFilePointer();
archive.seek(offset + 14);
archive.write(entryLater.array());
archive.seek(eof);
* Write the catalog data relevant to this entry. Buffer is
* preloaded with fixed data.
* @param buf Buffer to organise fixed lenght part of header
public void writeCatalog(ByteBuffer buf) throws IOException {
buf.position(12);
putDate(buf);
buf.putInt((int)crc);
buf.putInt(compressedSize);
buf.putInt(uncompressedSize);
buf.putShort((short)name.length);
buf.putShort((short)0); // extra field length
buf.putShort((short)0); // file comment length
buf.putShort(DISC_NUMBER); // disk number
buf.putShort((short)0); // internal attributes
buf.putInt(0); // external file attributes
buf.putInt((int)offset); // file position
archive.write(buf.array());
archive.write(name);
* This writes the entries date in MSDOS format.
* @param buf Where to write it
* @TODO Get this generating sane dates
public void putDate(ByteBuffer buf) {
long msTime = (date.getTime() - MSEPOCH) / 1000;
buf.putShort((short)(msTime % SECONDS_TO_DAYS));
buf.putShort((short)(msTime / SECONDS_TO_DAYS));
private Entry entryInProgress = null; // entry currently being written
private java.util.ArrayList catalog = new java.util.ArrayList(12); // all entries
* Start a new output file.
* @param name The name to store as
* @param date Date - null indicates current time
public java.io.OutputStream openEntry(String name, java.util.Date date) throws IOException{
if(entryInProgress != null)
entryInProgress.close();
entryInProgress = new Entry(name, date);
return this;
* Creates a new instance of ZipOutputFile
* @param fd The file to write to
public ZipOutputFile(java.io.File fd) throws IOException {
this(new java.io.RandomAccessFile(fd, "rw"));
* Create new instance of ZipOutputFile from RandomAccessFile
* @param archive RandomAccessFile
public ZipOutputFile(java.io.RandomAccessFile archive) {
this.archive = archive;
entryHeader.order(java.nio.ByteOrder.LITTLE_ENDIAN); // create fixed fields of header
entryLater.order(java.nio.ByteOrder.LITTLE_ENDIAN);
entryHeader.putInt(ENTRY_HEADER_MAGIC);
entryHeader.putShort(MIN_VERSION);
entryHeader.putShort((short)0); // general purpose flag
entryHeader.putShort(DEFLATE_METHOD);
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.clear();
cal.set(java.util.Calendar.YEAR, 1950);
cal.set(java.util.Calendar.DAY_OF_MONTH, 1);
// def.setStrategy(Deflater.HUFFMAN_ONLY);
MSEPOCH = cal.getTimeInMillis();
* Writes the master catalogue and postamble and closes the archive file.
public void close() throws IOException{
if(entryInProgress != null)
entryInProgress.close();
ByteBuffer catEntry = ByteBuffer.wrap(new byte[46]);
catEntry.order(java.nio.ByteOrder.LITTLE_ENDIAN);
catEntry.putInt(CATALOG_HEADER_MAGIC);
catEntry.putShort(VERSION_CODE);
catEntry.putShort(MIN_VERSION);
catEntry.putShort((short)0);
catEntry.putShort(DEFLATE_METHOD);
long catStart = archive.getFilePointer();
for(java.util.Iterator it = catalog.iterator(); it.hasNext();) {
((Entry)it.next()).writeCatalog(catEntry);
catEntry.position(0);
catEntry.putInt(CATALOG_END_MAGIC);
catEntry.putShort(DISC_NUMBER);
catEntry.putShort(DISC_NUMBER);
catEntry.putShort((short)catalog.size());
catEntry.putShort((short)catalog.size());
catEntry.putInt((int)(archive.getFilePointer() - catStart));
catEntry.putInt((int)catStart);
catEntry.putShort((short)0);
archive.write(catEntry.array(), 0, catEntry.position());
archive.setLength(archive.getFilePointer()); // truncate if old file
archive.close();
def.end();
* Closes entry in progress.
public void flush() throws IOException{
if(entryInProgress == null)
throw new IllegalStateException("Must call openEntry before writing");
entryInProgress.close();
entryInProgress = null;
* Standard write routine. Defined by {@link java.io.OutputStream}.
* Can only be used once openEntry has defined the file.
* @param b Bytes to write
public void write(byte[] b) throws IOException{
if(entryInProgress == null)
throw new IllegalStateException("Must call openEntry before writing");
crcAcc.update(b);
def.setInput(b);
while(!def.needsInput())
deflate();
* Standard write routine. Defined by {@link java.io.OutputStream}.
* Can only be used once openEntry has defined the file.
* @param b Bytes to write
public void write(int b) throws IOException{
oneByte[0] = (byte)b;
crcAcc.update(b);
write(oneByte, 0, 1);
* Standard write routine. Defined by {@link java.io.OutputStream}.
* Can only be used once openEntry has defined the file.
* @param b Bytes to write
* @param off Start offset
* @param len Byte count
public void write(byte[] b, int off, int len) throws IOException{
if(entryInProgress == null)
throw new IllegalStateException("Must call openEntry before writing");
crcAcc.update(b, off, len);
def.setInput(b, off, len);
while(!def.needsInput())
deflate();
* Gets a buffer full of coded data from the deflater and writes it to archive.
private void deflate() throws IOException {
int len = def.deflate(deflateBuf);
totalCompressed += len;
if(len > 0)
archive.write(deflateBuf, 0, len); -
Unable to override the method get(int) in java.util.AbstractList
package util;
import java.util.Vector;
import java.lang.Integer;
public class integerVector extends Vector
public integerVector() { //construct a Vector()
super();
public integerVector(int m) { // construct a Vector(m)
super(m);
public integerVector(int m, int n) { // construct a Vector(m,n)
super(m,n);
public void set (int i, int n) {
Integer ii= new Integer(i) ;
setElementAt(ii,n);
when i try compiling this i get the following error:
integerVector.java:37: get(int) in util.integerVector cannot override get(int) i
n java.util.AbstractList; attempting to use incompatible return type
found : java.lang.Integer
required: java.lang.Object
public Integer get(int n) {
It would be very helpful if anyone can provide the solutionThe method's signature is defined by the Interface java.util.List.
public Object get(int index)
instead you want to implement
public Integer get(int index)
Yes you could write a class with this method, and call it IntegerList or similar.
However it could not implement the List interface, or extend any of the List classes.
Instead of extending Vector (or ArrayList) you could delegate to it.
That way you're not extending the class, and not changing the signature of a method.
public class IntegerList(){
private List internalList = new ArrayList();
public Integer get(int index){
return (Integer)internalList.get(index);
}This class would be of limited use though, because you couldn't treat it as a regular list because it hasn't implemented the interface properly.
The best you could do would be to have it implement the collection interface, which doesn't expose the specific get methods. -
Why the Error in ArrayList Program : java.util.NoSuchElementException
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Collections;
import java.util.Random;
public class ArrayListDoubt {
public static void main(String[] args) {
// ArrayList Creation
List arraylistA = new ArrayList();
List arraylistB = new ArrayList();
// Adding elements to the ArrayList
for (int i = 0; i < 5; i++) {
arraylistA.add(new Integer(i));
arraylistB.add("beginner");
arraylistB.add("java");
arraylistB.add("tutorial");
arraylistB.add(".");
arraylistB.add("com");
arraylistB.add("java");
arraylistB.add("site");
// Iterating through the ArrayList to display the Contents.
Iterator i1 = arraylistA.iterator();
System.out.print("ArrayList arraylistA --> ");
while (i1.hasNext()) {
System.out.print(i1.next()+ " , ");
System.out.println();
System.out.print("ArrayList arraylistA --> ");
for (int j=0; j < arraylistA.size(); j++) {
System.out.print(arraylistA.get(j)+ " , ");
System.out.println();
Iterator i2 = arraylistB.iterator();
System.out.println("ArrayList arraylistB --> ");
while (i2.hasNext()) {
System.out.print(i2.next()+ " , ");
System.out.println();
System.out.println("Using ListIterator to retireve ArrayList Elements");
System.out.println();
ListIterator li = arraylistA.listIterator();
// next(), hasPrevious(), hasNext(), hasNext() nextIndex() can be used with a
// ListIterator interface implementation
System.out.println("ArrayList arraylistA --> ");
while (li.hasNext()) {
System.out.print(i1.next()+ " , ");
Output
ArrayList arraylistA --> 0 , 1 , 2 , 3 , 4 ,
ArrayList arraylistA --> 0 , 1 , 2 , 3 , 4 ,
ArrayList arraylistB -->
beginner , java , tutorial , . , com , java , site ,
Using ListIterator to retireve ArrayList Elements
ArrayList arraylistA -->
Exception in thread "main" java.util.NoSuchElementException
at java.util.AbstractList$Itr.next(AbstractList.java:427)
at ArrayListDoubt.main(ArrayListDoubt.java:58)System.out.println("Using ListIterator to
retireve ArrayList Elements");
System.out.println();
ListIterator li = arraylistA.listIterator();
next(), hasPrevious(), hasNext(), hasNext()
nextIndex() can be used with a
/ ListIterator interface implementation
System.out.println("ArrayList arraylistA -->
while (li.hasNext()) {
System.out.print(i1.next()+ " , ");
}I think you mean to call the next()-method of the ListIterator li, but instead call i1, which is an already used Iterator.
Where you want to iterate with ListIterator, change this line
System.out.print(i1.next()+ " , ");to this
System.out.print(li.next()+ " , ");and it works -
Is there a maximum for the classes in a package
I have strange problem
I have a project that have the data model in jar and it runs successfully
I tried to decompile the jar pacakge by package
the application still run tell i decompiled a package that have large number of classes 170 + 170 hibernate mapping file
then the application compile but not running and stop responding
i use jdeveloper 10.2.2.0 build 1929 and i cannot change to last versionThere is no such limitation.
You can't expect a decompiled java application to run as the original.
You should try to get hold of the java source instead of decompile some jars.
Timo -
Is there a maximum number for the classes in a package
I have strange problem
I have a project that have the data model in jar and it runs successfully
I tried to decompile the jar pacakge by package
the application still run tell i decompiled a package that have large number of classes 170 + 170 hibernate mapping file
then the application compile but not running and stop responding
i use jdeveloper 10.2.2.0 build 1929 and i cannot change to last versionThere is no such limitation.
You can't expect a decompiled java application to run as the original.
You should try to get hold of the java source instead of decompile some jars.
Timo
Maybe you are looking for
-
I'm thinking of replacing my iPhone 3GS with the N8 but hesitate as I haven't found any information on whether or not the media player in the N8 supports resume on large media files (audiobooks, podcasts and videos). Is the N8 capable of resuming pla
-
Hi Friends Could you please help me in the following issues?. I have a database two tables called Books and BSearch. When i search a Books Based on a Book category it should take the values related to that Category and store them all in the BSearch t
-
I was wondering if there was any store or business where i could take in a tape from my video camera and they will convert it to a disk for your computer.
-
Powershell. Concatenate varables to get object property
Hello, please give me hint I want concatenate varables to get object property. I have Variable $Item that is Object with properties and another variable $Parametr that is String type, its value is "EmailAddress". When try type $Item.$Parametr dont ge
-
Windows Live Hotmail and Apple Mail
Hey, So I'm using HTTPMail. But...it just doesn't work. Is it only supporting @hotmail.com accounts or does it support others such as @msn.com and @live.whatever It clearly talks to the server - as it tells me when I have an incorrect password, but i