Objects to Strings
Hi All
Am having a Vector containing collections of Objects
I want to retrieve that and convert in to String(using Enumeration too)
I tried this String name=(String)E.nextElement();
but this is not working
Give me Solution... Or else tell me whether Java.lang.Object in to String type is possible
Aski
ok Please find out the problem here
Sting name="abc"
static Vector currentUsers=new Vector();
currentUsers.add(names);
Enumeration listAll=currentUsers.elements();
String user;
while(listAll.hasMoreElements())
user=(listAll.nextElement()).toString();
System.out.println(user);
I am expecting this code to print abc. But it is giving NoSuchElementException . Can anyone findout me the problem
Thanks All
Similar Messages
-
Object convert String (=' '=)""-- URGENT
I need to convert few object to string, how i use toString() to convert it ???
Actually i writing JFormattedTextField, my JFormattedTextField.getValue() which return object, it cause me problem to write a condition checking.e.g checking for null.....
I had try with JFormattedTextField.toString(), error..... -
Converting Spatial Objects to strings
Hi,
Many tools (SQL*Plus, DBVisualizer, various Python modules) seem to be able to retrieve spatial objects as strings. Is this conversion being done by each tool, or does the database know how to convert objects (at least Oracle Spatial objects) to strings?
Is there any way to get string as the result of a query of an Oracle Spatial object with Pro*C or the other precompilers?
Thanks for any information,
-- Andrew Bell
[email protected]Andrew
Is your question about decoding the struct returned in an OCI, Pro*C, or SQLJ program to get at the fields of an sdo_geometry type?
There are oci examples (readgeom.c, writegeom.c) on OTN.
Jayant -
Reference to an object by String(ID)?
I am trying to build a glow container/manager in order to
turn off and turn on appropriate component. In fact, when a
specific component respond to a click, it will be glowed. But if
the user click on another specific component, the previous glowed
should unglow and the new one will be glowed.
Now, to do this, I created a class with 2 elements:
objReference:String and glowActive:Boolean. I also created an
ArrayCollection of all the component that can respond to the glow
effect and put them inside like this:
objReference = [object].ID
And every component get FALSE for glowActive at the
initiation of the ArrayCollection.
I have a problem with the recognization of the object ID.
When I tried to play the glow using the objReference, the system
indicate the following error:
TypeError: Error #1006: value is not a function.
at
mx.effects::EffectInstance/play()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\effec ts\EffectInstance.as:584]
at
mx.effects.effectClasses::GlowInstance/play()[E:\dev\3.0.x\frameworks\projects\framework\ src\mx\effects\effectClasses\GlowInstance.as:194]
at
mx.effects::EffectInstance/startEffect()[E:\dev\3.0.x\frameworks\projects\framework\src\m x\effects\EffectInstance.as:569]
at
mx.effects::Effect/play()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\effects\Effec t.as:930]
at accueil/setCategoryGlowIn()[C:\Documents and Settings\DJ
FYB\My
Documents\CharlesValcourt\includes\charlesvalcourt_logique.as:303]
at accueil/clickCategoryBox()[C:\Documents and Settings\DJ
FYB\My
Documents\CharlesValcourt\includes\charlesvalcourt_logique.as:282]
I am a bit confuse on how to call an object by reference and
stored the referene of the object in somewhere else (in my case, in
a ArrayCollection).Youpi!!! I found how to made it!!!
First, I finally have to make the property objReference in my
class GlowObjectReferencer as an Object in order to work.
Than, I have to pass myHB as the Object (which, if I
understand properly, will put a reference of the current Object
into the new class Object).
var _objReference:GlowObjectReferencer = new
GlowObjectReferencer (myHB, false);
And when I run my functions to manage the Glow FX
(setAllCategoryGlowOut and setCategoryGlowIn), it is now working
fine!!!
I am so happy now! I knew it was possible but in my mind, it
was just not logic to store an Object in the class but it seems
that it is what I need to do! But just to make sure: what I pass to
the class GlowObjectReferencer as the first property is only the
reference to myHB? Not a copy of myHB; right?
Again, thank Tracy because you force me to find the way to do
it!!! ;-)) -
Dynamically instantiating objects using string name
Hello to all.
This is probably an easy question, but I am wondering how I can dynamically create instances of an object in a loop using a string variable as the name.
The idea here is this:
while (someBooleanVariable) {
int count = 1;
String objectName = "myObject" + count;
myObject objectName = new myObject; // How do I pass the objectName String variable as a name?
count++;
} // End while
Of course this doesn't work - incompatible types, but the idea is that the code would create "myObject1," "myObject2," "myObject3," "myObject4," etc as long as someBooleanVariable = true using the objectName String variable.
I am new to this and appreciate any help and ideas.
Thanks!BigDaddyLoveHandles wrote:
There's been this outbreak of people wanting to dynamically name their variables -- is this some sort of scripting disease?It's always been around. Shoot, I remember suffering from it when I first started out, because it seems so, hm I dunno, necessary at the time. Eventually the newbie (me) realizes that the variable "name" means nothing, that reference is everything.
... and then I discovered maps, and names were useful again. :o) -
Converting the scanner object into string object....
Hello everyone. I've finished my hw and one thing made me curious about it. I hope you can help me. Now, I've tried to make this code in NetBeans IDE 6.0:
Scanner src = new Scanner(System.in);
String s = src.toString().toLowerCase(Turkish /* locale thing*/);
My purpose is to take users entries to console as string and than make the letters in lower case. But, my language is turkish. So I've problem with it because there is no Locale Turkish object in IDE.
So what do you suggest. Do you know a downloadable or updatable solution for this. Or if you're sure that there is no prepared solution, what do you suggest.I've looked that page but I've found some of the answers at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#toLowerCase(java.util.Locale)
I knew that I can't write a code like that. I was just wondering if I could change the locale (after I initialize the string obj.) while toLowerCase().
I needed that becouse when I want to ask a question at console: I must ask it in whatever user's language is. And also get the answers in their own language. Then I'll match the answers with my answers. for example console will ask:
please enter your language? T?rk?e, English, Dutch, ?vrit, ...
and the user will enter some characters to chose their language IN THEIR OWN ALPHABET that I'll match those with the ones that I created the answers (inside the codes) in all languages.
If there is a match the program will work with that alphabet.
I was asking for an easier way to get on with this. There may be a class that I can reach any kind of alphabets. or a method maybe. -
Query Operator "IS" is not working good for object type "String"
Hi,
I have a problem with advanced search. When the object type is String, and I want to search directly value (for exemple 'a') i have returned all value starts with 'a', even though I set Query Operator to "IS"
When I use Query operator "setByUser", and then set property to "IS", query behaviour is correct.
Behaviour example for operator "IS":
values: a, ab, abc
searching: 'a' --> expected results: a results: a, ab, abc
Any sugestions??
Sorry for my English
Regards,
Wojciech MularczykSyed,
Only under advanced search. The operator used for quick search is defined through two properties in JhsAdvancedSearch bean class:
private String defaultStringOperator = "startsWith";
private String defaultNonStringOperator = "is";
So, if you have a String attribute which holds numbers and you want to apply the "is" operator to this attribute, you can change the default value of "defaultStringOperator" by creating a custom template for searchBean.vm, and add the following property:
<managed-property>
<property-name>defaultStringOperator </property-name>
<value>is</value>
</managed-property>
Note hat you can already apply this technique in the current release.
Steven Davelaar,
JHeadstart Team. -
Converting objects into Strings
How would someone convert an object of say (String, int, double, String) into a readable string. I tried the toString() method but all I get is something like this
Student@1f12c4e..I'm not sure I understand "how" to override. The whole point of this project is to use quicksort on a list of students, unfortunately all I get is the address whenever I use the .toStrings() method.
Here's what I have, any help would be greatly appreciated-so very close
import cs1.Keyboard;
import java.io.*;
import java.util.*;
public class StudentTraverse
public static void main(String[] args)
String newName;
int newSocial;
double newGPAs;
String newMajors;
System.out.println("How many Students would you like to add");
Student newStudent;
StudentList12 WORK = new StudentList12();
int total = Keyboard.readInt();
for(int number = total; number > 0; number--)
System.out.println("Name?");
newName = Keyboard.readString();
System.out.println("Social?");
newSocial = Keyboard.readInt();
System.out.println("GPA?");
newGPAs = Keyboard.readDouble();
System.out.println("Major?");
newMajors = Keyboard.readString();
newStudent = new Student(newName, newSocial, newGPAs, newMajors);
System.out.println("Inserting: "+newStudent.toString());
WORK.add(newStudent);
for(total = 0; total < WORK.size(); total++)
System.out.println("top" total": "+WORK.top(total).toString());
try
BufferedReader in = new BufferedReader(new FileReader("LIST.out"));
while (in.ready())
// Print file line to scree
System.out.println (in.readLine());
in.close();
catch (Exception e)
System.err.println("File input error");
public class StudentNode
public Student student;
public StudentNode next;
public StudentNode()
next = null;
student = null;
public StudentNode(Student d, StudentNode n)
student = d;
next = n;
public void setNext(StudentNode n)
next = n;
public void setData(Student d)
data = d;
public StudentNode getNext()
return next;
public Student getData()
return data;
public String toString()
return ""+data;
public StudentNode(Student newStudent)
METHOD NAME: StudentNode
AUTHOR:
DATE OF CREATION: Nov 20, 2004
DATE OF UPDATES: Nov 28, 2004
PURPOSE: Acts as a node for the Student list
ALGORITHM:Acts as node for the list
INSTANCE VARIABLES: none
student = newStudent;
next = null;
public class Student
private String name;
private int social;
private double GPA;
private String Major;
public Student(String newName, int newSocial, double newGPAs, String newMajors)
METHOD NAME: Student
AUTHOR:
DATE OF CREATION: Nov 20, 2004
DATE OF UPDATES: Nov 28, 2004
PURPOSE: The actual Student class, determines what is allowed in the array
ALGORITHM:Declare what variables will be needed for the program
INSTANCE VARIABLES: String name, int social, double GPA, String Major
name = newName;
social = newSocial;
GPA = newGPAs;
Major = newMajors;
import java.io.*;
import cs1.Keyboard;
import java.io.BufferedWriter;
import java.util.*;
public class StudentList12
private StudentNode list;
static int i = 0;
public StudentList12()
METHOD NAME: StudentList12
AUTHOR:
DATE OF CREATION: Nov 20, 2004
DATE OF UPDATES: Nov 28, 2004
PURPOSE: Declares the Node
ALGORITHM:Declare the Node
INSTANCE VARIABLES: none
list = null;
public boolean isEmpty()
return list == null;
public int size()
return i;
public void add(Student newStudent)
METHOD NAME: add
AUTHOR:
DATE OF CREATION: Nov 20, 2004
DATE OF UPDATES: Nov 28, 2004
PURPOSE: Let's users add objects to the array of objects
ALGORITHM:Traverses the current list and adds object to the end
INSTANCE VARIABLES: none
list = new StudentNode(newStudent, list);
i++;
current = current.next;
current.next = node;
public Student remove()
if(isEmpty())
return null;
StudentNode tmp = list;
list = tmp.getNext();
i--;
return tmp.getData();
public void insertEnd(Student newStudent)
if(isEmpty())
add(newStudent);
else
StudentNode t = list;
while(t.getNext() != null)
t=t.getNext();
StudentNode tmp = new StudentNode(newStudent, t.getNext());
t.setNext(tmp);
i++;
public Student removeEnd()
if(isEmpty())
return null;
if(list.getNext() == null)
return remove();
StudentNode t = list;
while(t.getNext().getNext() != null)
t = t.getNext();
Student newStudent = t.getNext().getData();
t.setNext(t.getNext().getNext());
i--;
return newStudent;
public Student top(int n)
StudentNode t = list;
for(int i = 0; i <n && t != null; i++)
t = t.getNext();
return t.getData();
public void writeToFile(int n)
int z = n;
try
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("LIST.out")));
for(int counter = z; counter >= 0; counter--)
System.out.println(counter);
out.close();
catch(Exception e)
System.err.println("Couldn't Write File");
try
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("LIST.out")));
out.write(list.toString());
out.close();
catch(Exception e)
System.err.println("Couldn't Write File");
} -
Hello,
In my program i am considering of inserting string or object in a hashmap
String term;
map.put(key, term)
or
map.put(key new String(term))
which one is most efficient?Hi Nilsen,
I would think that map.put(key, term) is far more efficient. Instanciating a new object is always expensive. Java references strings in a way that minimizes the memory and CPU. If you have a reference in one class to a string "string", and another reference to an exact duplicate "string" in another class in fact the JVM references the same String object in memory, this is why Strings are not malleable as they are referenced by potentially many classes, i.e. changing the string from one class would affect the reference from the next.
So to make a short story long, the first option would be much more efficient.
See ya
Michael -
String object vs String literal
Hi ,
I understand how the string objects are created using new operator and using literal.I also understand how they are stored in memory.All I want to know is that when and why should I create a String object using new and when I should create an object using literal.Is there any specific reason for creating an object using new operator when objects created by both the ways are immutable.
Thanks for the help in advance.
Thanks
MouliIf you look at the String source code (particularly the constructors) youll learn a lot.
String objects contain a char[] array - and this is the most important part --> a start and length value.
I believe they were attempting to optimize, but this has important implications for developers.
String objects dont necessarily store just the text you see, it may just reference a much bigger char array.
For example, say an API passes you a string that is (lets pretend) a file path (C:\files\java\...\file.txt) that is 1,000,000 characters long.
Now say that you call getFileName() and want to save the filename in a list.
String filename = API.getFile("...").getFileName();
List.add(filename);
Say you do this about 250,000 times.
You estimate that the average file name is 10 chars and ensure there is that much RAM.
You run out of memory. Why?
Well, this example actually happened to me in a real program I was writing to archive drive files.
File.getFilename() returns a substring() of the entire File path.
However, substring is implemented to return a String that just references the original char[] array!
So the really long file path never gets garbage collected!
I was able to fix the program by coding it:
String filename = new String(API.getFile("...").getFileName()); // Copies only the needed chars!
List.add(filename);
So thats really all you need to watch out for. If memory is a concern in your program you want to
make sure you arent referencing large char[] arrays unnecessarily.
But like all things, this is rarely anything to give much thought to.
Only something to remember if you run into problems after coding sensibly and profiling
(or in my case, crashing with OOM exceptions, lol). -
Getting Color object from String
hi
i need to get a Color object from a string provided at runtime.ie for the string "RED" i need to get a object of Color.RED.I have already tried to use decode() from Color class but it throws numberformat exception,can someone guide me.Color.decode(String) will decode octal and hexidecimal representations of colors e.g.
Color poo = Color.decode("0x215DB8"); // hex description of color
works.
If you want to use RED, BLUE ... read them at run into a String or whatever and then test this String to get what color the user wanted e.g.
read from text file at run time that button colour should be ORANGE.
In your code, put
String colourStr; // read what colour the user specified into this var
Color their_color = null;
if(colour.equals("ORANGE"))
their_color = new Color(Color.orange);
else if(colour.equals("BLACK"))
// you can guess what goes here.. and so on.
It often nice to make them specify the hex value of the colour because there are more of these than the predefined colours (shock horror).
Anyway,
seeya, Edd. -
New object (with string)
Hello,
I have a function which is getting as an input a string variable and needs to create an new object that has the same name as the input string.
How can I do it?
thanksHello,
I have a function which is getting as an input a
string variable and needs to create an new object
that has the same name as the input string.
How can I do it?For me the main question is why you want to do this? What difference is the name of the as long as you can find the object. I wonder if there is a better way of implementing what it is you want to do.
For instance, would tying your object to the string via HashMap be a better solution?
Do you have any sample code or pseudocode showing what you want to do?
Message was edited by:
petes1234 -
Create MIME Object with String
Hello,
I have a string value containing a MIME message. What I want to do now is to parse the date out of this message. My idea was to create a MIME object type first and then using some getter methods to parse the DATE of the MIME header.
So basically the question is how I create a MIME object out of the string. Any idea on this?
Thank you very much.Hi again Florian,
Maybe a glance at those pages could help you :
http://jigsaw.w3.org/Doc/Programmer/api/index.html?org/w3c/www/mime/MimeParser.html
http://docs.sun.com/source/816-6028-10/asd3j.htm#1047313
http://james.apache.org/mime4j/apidocs/index.html?org/apache/james/mime4j/parser/MimeStreamParser.html
Not sure those classes could be easily used and imported into XI/PI, but if you can avoid writing your own parser, that'd be great
Chris -
Safari fails to recognize object as string
I created the page http://epoch.chem.uky.edu/epoch-plugin/public/indexOfTest2.jsp to illustrate what appears to be a new bug in Safari. Click on any drawing in the bottom toolbar, click in the drawing space, and press the button underneath. Two alerts come up. They are created by this JavaScript code:
function getIndexOf() {
var testStr = document.responseApplet.getMol("mrv");
alert("testStr is " + (typeof testStr)
+ ", testStr.indexOf('?x') = " + testStr.indexOf('?x')
+ ", testStr.indexOf('x2=') = " + testStr.indexOf('x2=')
+ ", testStr=\n" + testStr);
testStr = '' + testStr;
alert("after modifying testStr, testStr is " + (typeof testStr)
+ ", testStr.indexOf('?x') = " + testStr.indexOf('?x')
+ ", testStr.indexOf('x2=') = " + testStr.indexOf('x2=')
+ ", testStr=\n" + testStr);
You can see that when Safari retrieves the value from the applet, it thinks it has the type object, and it is unable to find the requested substrings in the value. On the other hand, Firefox 3.0 for Mac and InternetExplorer 7.0 for PC know right away that the retrieved value is a String. Interestingly, Firefox 2.0 for PC says that testStr is an object, but it is still able to find the substrings in the returned value. Only Safari is unable to find the substrings.
This appears to be a new behavior for Safari. I have been using this applet for years and have never had this problem previously.
Anyone have any ideas why this is happening?HI Robert,
Not sure what's causing the bug but you can report it.
From the Safari Menu Bar, click Safari/Report Bugs to Apple...
Carolyn -
Creating Objects with String name
How can i create an object, but just having the name as String?
Like, instead of creating like JInternalFrame obj = new MyInternalFrame(), do it like JInternalFrame obj = createObject("MyInternalFrame") ( i just gave createObject as example, ignore it)...
Does anyone knows how to do it? Because i have several windows, and by clicking, i dont want to be with a lot of if clauses checking each one to se wich one is the ritgh class to call...
Tks,
BrunoYou need the Class class in package java.lang, specifically class (static) method forName() and instance method newInstance():
JInternalFrame obj =
(JInternalFrame) Class.forName("MyInternalFrame").newInstance();
Maybe you are looking for
-
Inserting text over an image in dreamweaver cc
I am trying to insert text over an image in fluid grid layout but all i can see is the text. I have seen the previous query relating to this but it does not help. Help on this would be great.
-
LR4 beta white balance on cropped images
I'm not sure if this has been discussed, I could not find a post with silimar issues. LR4 Beta 64 on WinVista : Nex 5N raw files WB picker on a cropped image seems to give variable (and wrong) results I wanted to tweak WB an image that I'd previously
-
Forgot Time Capsule Password Can't access it
Hi There, this must be a no brainer, but I've made a mistake assuming I had the correct password for my TC. I've erase the disc of my 24'' in order to sell the machine, bought a new 27'' and when I tried to access Time Capsule to retrieve all of
-
How to restore IOS 6 I do not like IOS 7 ?
Since I changed to IOS 7 on both my I-Pad and iPhone I do not like it at all and wish to come back to previous. Is it possible and if yes how please help !
-
CRM 2007 Java Upgrade to CRM 7.0 EHP2
Hi All, I performed dual stack split in CRM 2007 with separate DB for ABAP and JAVA. For upgrading CRM 2007 I tried generating solman XML file. For CRM 2007 Java, the target is chosen as CRM 7.0 EhP2, but the Net weaver components are showing the cur