Urgent String question
The effect of repeated concatenation of Strings can cause a lot of unwanted objects in memory. If I am creating a query statement as follows:
String query = "Select * from"+tablename+"where something "+x+"something"+y.......(All in a single statement)
Willl this also create a lot of unwanted objects before query finally gets its value? Should I do this concatenation with a stringbuffer?
I found the following listing and hope it helps...
http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#39990
15.18.1.2 Optimization of String Concatenation
An implementation may choose to perform conversion and concatenation in one step to avoid creating and then discarding an intermediate String object. To increase the performance of repeated string concatenation, a Java compiler may use the StringBuffer class or a similar technique to reduce the number of intermediate String objects that are created by evaluation of an expression.
For primitive types, an implementation may also optimize away the creation of a wrapper object by converting directly from a primitive type to a string.
Hope this also helps.
Similar Messages
-
Urgent SQL question : how to flip vertical row values to horizontal ?
Hello, Oracle people !
I have an urgent SQL question : (simple for you)
using SELECT statement, how to convert vertical row values to horizontal ?
For example :
(Given result-set)
MANAGER COLUMN1 COLUMN2 COLUMN3
K. Smith ......1
K. Smith ...............1
K. Smith ........................1
(Needed result-set)
MANAGER COLUMN1 COLUMN2 COLUMN3
K. Smith ......1 .......1 .......1
I know you can, just don't remeber how and can't find exactly answer I'm looking for. Probably using some analytic SQL function (CAST OVER, PARTITION BY, etc.)
Please Help !!!
Thanx !
Steve.scott@ORA92> column vice_president format a30
scott@ORA92> SELECT f.VICE_PRESIDENT, A.DAYS_5, B.DAYS_10, C.DAYS_20, D.DAYS_30, E.DAYS_40
2 FROM (select t2.*,
3 row_number () over
4 (partition by vice_president
5 order by days_5, days_10, days_20, days_30, days_40) rn
6 from t2) f,
7 (SELECT T2.*,
8 row_number () over (partition by vice_president order by days_5) RN
9 FROM T2 WHERE DAYS_5 IS NOT NULL) A,
10 (SELECT T2.*,
11 row_number () over (partition by vice_president order by days_10) RN
12 FROM T2 WHERE DAYS_10 IS NOT NULL) B,
13 (SELECT T2.*,
14 row_number () over (partition by vice_president order by days_20) RN
15 FROM T2 WHERE DAYS_20 IS NOT NULL) C,
16 (SELECT T2.*,
17 row_number () over (partition by vice_president order by days_30) RN
18 FROM T2 WHERE DAYS_30 IS NOT NULL) D,
19 (SELECT T2.*,
20 row_number () over (partition by vice_president order by days_40) RN
21 FROM T2 WHERE DAYS_40 IS NOT NULL) E
22 WHERE f.VICE_PRESIDENT = A.VICE_PRESIDENT (+)
23 AND f.VICE_PRESIDENT = B.VICE_PRESIDENT (+)
24 AND f.VICE_PRESIDENT = C.VICE_PRESIDENT (+)
25 AND f.VICE_PRESIDENT = D.VICE_PRESIDENT (+)
26 AND f.VICE_PRESIDENT = E.VICE_PRESIDENT (+)
27 AND f.RN = A.RN (+)
28 AND f.RN = B.RN (+)
29 AND f.RN = C.RN (+)
30 AND f.RN = D.RN (+)
31 AND f.RN = E.RN (+)
32 and (a.days_5 is not null
33 or b.days_10 is not null
34 or c.days_20 is not null
35 or d.days_30 is not null
36 or e.days_40 is not null)
37 /
VICE_PRESIDENT DAYS_5 DAYS_10 DAYS_20 DAYS_30 DAYS_40
Fedele Mark 35473 35209
Fedele Mark 35479 35258
Schultz Christine 35700
South John 35253
Stack Kevin 35701 35604 35402 35115
Stack Kevin 35705 35635 35415 35156
Stack Kevin 35706 35642 35472 35295
Stack Kevin 35707 35666 35477
Stack Kevin 35667 35480
Stack Kevin 35686
Unknown 35817 35698 35596 35363 35006
Unknown 35702 35597 35365 35149
Unknown 35724 35599 35370 35155
Unknown 35600 35413 35344
Unknown 35601 35451 35345
Unknown 35602 35467
Unknown 35603 35468
Unknown 35607 35475
Unknown 35643 35508
Unknown 35644
Unknown 35669
Unknown 35684
Walmsley Brian 35725 35598
23 rows selected. -
The only thing i need to do is add a title or label attribute to some of the controls.
One of the ones to begin with that i am fixing is the ADF tag af:selectBooleanRadio. When i add some text to the shortDesc field of the control, the html is produces doesn't have the title attribute.
So i tried to use the corresponding trinidad control tr:selectBooleanRadio, and add some text to the same shortDesc field for the control, and in this case it does add a title attribute in the html that it produces.
Everything else in the code works fine as well when i add the trinidad control, except for one thing. I have a ValueChangeListener that gets called when you click on another tr:selectBooleanRadio. Within that valueChangeListener event handler function, i have a bunch of code which in the end displays a af:popup. The problem i am having when using the trinidad control is that it somehow is not allowing the display of the popup even though it is going through the code that executes display of the popup. When i click on another link or button that is supposed to display a different popup as well, then the popup associated with the tr:selectBooleanRadio also displays at that time, but not originally when the value changed by selecting a different tr:selectBooleanRadio.
So, my question is, are there any other successful ways of adding a title attribute to the these controls. If its the af:selectBooleanRadio how do we make it so that the html it generates has the title attribute, or if its the tr:selectBooleanRadio, what might be happening during the event handling that it is not allowing the af:popup to display?
A quick response to this appreciated since this is very urgent! Thanks very much for your help!JDev version is 11.1.1.5
ok, i will go one step at a time so that it is easy to understand. So i will only mention the first thing right now and then we can try other things later.
i have a af:selectBooleanRadio. After running the page/application, when the user does View Source in the browser for the page that has the radio button, it is in the form of an HTML tag <input> of type for radio button. What i want to do is to have a "title" attribute for the <input> tag for this radio button. I can use the tr:selectRadioButton trinidad control to do that, but then i have other issues with that, and we can talk about those later.
Let me know if it is still not clear.
Thanks very much for your help! -
Help please - urgent exam question
I'm having difficulty with the following question for an OU exam:
You will now create a method to enable students to make a list of the books they have read, whether they are on the course�s reading list or not.
Add an instance method to the class, with the header: public Set<String> collectBooksRead()
The method should first declare a local variable of type Set called readBooks capable of holding a set of strings.
The method should then assign to that variable an appropriate set object.
The method should then use a dialogue box to collect the book titles one at a time from the user.
The dialogue box should have the prompt "Please input a book title or * to finish", and should have an empty string as its default reply.
Each entered book title should be added to the set referenced by the local variable readBooks. Finally the method should return readBooks as the message answer.
Here's my code so far but it endlessly loops and I'm unsure how to make it stop.
public Set<String> collectBooksRead()
Set<String> readBooks = new HashSet<String>();
String title;
do
title = OUDialog.request("Please input a book title or * to finish",""); //OUDialog.request displays an input dialogue box as specified by a superclass
readBooks.add(title);
while
(title != "*");
}I'm having difficulty with the following question for
an OU exam:
You will now create a method to enable students to
make a list of the books they have read, whether they
are on the course�s reading list or not.
Add an instance method to the class, with the header:
public Set<String> collectBooksRead()
The method should first declare a local variable of
type Set called readBooks capable of holding a set of
strings.
The method should then assign to that variable an
appropriate set object.
The method should then use a dialogue box to collect
the book titles one at a time from the user.
The dialogue box should have the prompt "Please input
a book title or * to finish", and should have an
empty string as its default reply.
Each entered book title should be added to the set
referenced by the local variable readBooks. Finally
the method should return readBooks as the message
answer.
Here's my code so far but it endlessly loops and I'm
unsure how to make it stop.
unplug the computer. works every time -
Hi!
I have two questions:
1) Can I do toString() on a null value?
2) Is there any difference in writing:
String s = new String();
and
String s;isnt it true that in the first case s -object of
String class is created??Yes, the empty string, length zero, as he said.
>
in second case just defining a variable type String??Yes. It will either be null or have an udefined value, depending on whether it's a member variable or a method variable. -
URGENT : Challenge questions query: Oracle Access Manager 10g
Hi all,
This is a query regarding password challenge questions in Oracle Access Manager 10g. We have created password policies for a specific container in OID (say cn=xxx,cn=users,dc=oracle,dc=com) and it is working fine.
In order to exclude certain set of users (say user ABC ) for password policies, we have set the obpasswordchangeflag to false for those users which are in same container for which password policy is created.
When we try to login to the application with the user say ABC, I am not seeing any reset password page - I am happy till this point. However it is showing Configure Challenge questions page. Is there any way to bypass this page? Or is this the expected behavior?
This is very urgent and prompt reply is very much appreciated.
-MahendraHi Mahendra,
This is expected behaviour. In order to exclude the password policy management for some certains user for particular domain/container. please add the below configuration parameter to your OAM10g password policy.
Password Policy Filter Field (!(|(cn=xxx)(cn=abc)))
----Ajay -
Convert string question... "\"
I try the below code on jsp, but result is : a , a\b
but I want the result is : a\\b, a\\\\b
Thanks !
<%
String str = "a\b, a\\b";
String outStr = "";
for (int i=0;i<str.length();i++){
char c = str.charAt(i);
if (c == '\\'){
outStr += "\\";
else{
outStr += c;
%>
<%=outStr%>Right, because the compiler interprets "\\" as an escape character, indicating that you want a backslash. (If you tried to just use a String "\", you'd probably get a compilation error, since the compiler would think you were trying to escape the second quotation).
I think you're going to need to use RegExp... this question has been asked a bunch before, so search through the forums for an answer. -
Hello,
I have the next problem:
I have cursor that contains the next thing:
WHERE LKP_INDUSTRY1_ID IN ( p_sector )
p_sector is being delivered in varchar: '23;22;36'
My question is: is it possible to manipulate p_sector in a way that I can paste it in my cursor? I can replace the ';' with ',' but I don't know how I can make it read the numbers as numbers and not as strings.
Thanks in advance.
OliDoes this solve your problem ?
SQL> create or replace type tab_n is table of number;
2 /
Type created.
SQL> declare
2 p_sector varchar2(20) := '7369;7499;7521';
3 t tab_n := tab_n();
4 element number;
5 pos integer := 0;
6 cursor a is select ename from emp where empno in (select * from table(t));
7 begin
8 for i in 1..length(translate(p_sector || ';',';0123456789',';')) loop
9 t.extend;
10 t(t.count) := substr(p_sector,pos+1,instr(p_sector || ';',';',1,i)-pos-1);
11 pos := instr(p_sector,';',1,i);
12 end loop;
13 for v in a loop
14 dbms_output.put_line(v.ename);
15 end loop;
16 end;
17 /
SMITH
ALLEN
WARD
PL/SQL procedure successfully completed.Rgds. -
Urgent - help question on sending http instead of https
I'm trying to dump out my http wrapper: I'm trying to set send http instead of https so I can dump the wrapper.
currently my code does the following for https determination. i read from a configuratioin file to see if i should set https or http
question) Do i need an else section to cover non https?
If so, what do i need to set for http properties.
// check if https is wanted
// yes - send https
String useHttps = cf.get("useHttps", "true");
if (useHttps.equals("true")) {
logger.debug(classMethod + "https mode=" + useHttps);
System.setProperty(
"java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
// make provider and/or protocol configurable?
Security.addProvider(
new com.sun.net.ssl.internal.ssl.Provider());
}resolved - don't need help anymore on it
-
Urgent constructor question..
I'm trying to call this Flower class in another class called Garden, in which I created a new Flower by using a statement
private Flower lastflower;
and it's saying it cannot find the symbol - constructor Flower.
Can anyone tell me why and help correct this problem?
Below is the code for my Flower class.
Any help is really appreciated, it's for my Java class!
import objectdraw.*;
import java.awt.*;
* Write a description of class Flower here.
* @author (your name)
* @version (a version number or a date)
public class Flower
protected FilledOval dot;
protected FilledRect stem;
protected FilledOval petal1;
protected FilledOval petal2;
protected static final int boundary = 100;
protected RandomIntGenerator colorGen =
new RandomIntGenerator(0,255);
protected Color petalColor;
protected Boolean flowerContains=false;
private DrawingCanvas canvas;
public void changeColor(){
dot = new FilledOval(150,150,15,15, canvas);
dot.setColor(Color.YELLOW);
petalColor = new Color(colorGen.nextValue(),
colorGen.nextValue(),
colorGen.nextValue());
petal1.setColor(petalColor);
petal2.setColor(petalColor);
public void grow(Location point){
stem = new FilledRect (dot.getX()+3, dot.getY()+10, 10, 10, canvas);
stem.setColor(Color.GREEN);
if (dot.getY()>boundary){
dot.move(0,-4);
else{
petal1 = new FilledOval(dot.getX()-12, dot.getY()-25, 40,70,canvas);
petal2 = new FilledOval(dot.getX()-25, dot.getY()-10, 70,40,canvas);
dot.sendToFront();
stem.sendToBack();
petal1.setColor(petalColor);
petal2.setColor(petalColor);
public Boolean flowerContains(Location point){
if (petal1.contains(point)){
return true;
else if (petal2.contains(point)){
return true;
else if (dot.contains(point)){
return true;
else{
return false;
}I don't care how fucking urgent you think it is, it isn't to us. We will answer your question when and how we feel llike it. Have some manners and if you must, then bump your original post. Don't create another time wasting piece of crap!
-
Concat substring and string question
Hello,
So I am trying to add together a string \\fafs10\home and the concat of a substring of the first initial of a GivenName and LastName. I keep getting a NaN error.
Here's what I have:
=string("\\fafs10\home\") + concat(substring(GivenName,0,1), LastName)
I want to return this as a default value to my list.
Any help would be greatly appreciated. Thank you.
MatthewHi
are you doing this in a calculated column or within a rule on an InfoPath form or another way?
you should probably just go with
concat("\\fafs10\home\",substring(GivenName,0,1),LastName)
Regards
Sergio Giusti Sergio Blogs
Linked
In Profile
Whenever you see a reply you think is helpful, click Vote As Helpful.
Whenever you see a reply you think is the answer to the question, click Mark As Answer. -
A slightly unusual String question
Hi everybody,
Does anyone know if there is a limit to how long Strings can be? I'm parsing an html file and the opening and closing paragraph tags are not always on the same line. The only way I could think of to make sure I parsed out the paragraphs correctly was to squish the whole HTML body (which is very long) into one big String and scan through it for the tags. Hence my question; I don't want to kill my JVM with an OutOfMemoryError.
Any help on this would be great.
Thanks,
Jezzica85extract from word docs you say?
ive done that
package com.doesthatevencompile.desktopsearch.filetypes.framework.msdoc;
import org.apache.lucene.document.Document;
import org.textmining.text.extraction.WordExtractor;
import com.doesthatevencompile.desktopsearch.filetypes.framework.DocumentFieldHelper;
import com.doesthatevencompile.desktopsearch.filetypes.framework.DocumentHandler;
import com.doesthatevencompile.desktopsearch.filetypes.framework.DocumentHandlerException;
import java.io.InputStream;
public class TextMiningWordDocHandler implements DocumentHandler {
public Document getDocument(InputStream is)
throws DocumentHandlerException {
String bodyText = null;
try {
bodyText = new WordExtractor().extractText(is);
catch (Exception e) {
throw new DocumentHandlerException(
"Cannot extract text from a Word document", e);
if ((bodyText != null) && (bodyText.trim().length() > 0)) {
Document doc = new Document();
DocumentFieldHelper.addFieldToDocument(doc, DocumentFieldHelper.KEYWORD_ALL_TEXT, bodyText);
DocumentFieldHelper.setDocumentType(doc, DocumentFieldHelper.TYPE_DOC);
return doc;
return null;
}the lib you need can be found here:
http://doesthatevencompile.com/current-projects/code-sniplets/lib/
called tm-extractors
there is some lucene code mixed in the code sniplet which you dont need to worry about. hopefully this is enough to set you on your way -
I would like to know how to make a string with the same characters as another string. Also, how can I set an int with the same value as there are characters in a string. It would really help if you gave me an example, because I am new to java and pretty much lost.
That page has alot of information, but I really don't
know how to use any of it. It would be really helpful
is some one gave me an example. I see something like
"int length ( )", but I don't know how to use it.You don't know how to call a method? Then you need to start from the very beginning:
Sun's basic Java tutorial
Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's Thinking in Java (Available online.)
Joshua Bloch's Effective Java
Bert Bates and Kathy Sierra's Head First Java.
James Gosling's The Java Programming Language. Gosling is
the creator of Java. It doesn't get much more authoratative than this.
Here's a freebie though:String str = ...;
int len = str.length(); -
is there a way to remove a character from a string, for example:
"< head>"
and do some sort of trim to it to create
"<head>"
thankshalfpipehippie wrote:
is there a way to remove a character from a string, for example:
"< head>"
and do some sort of trim to it to create
"<head>"
thanksreplaceAll(...) can handle this quite easily:
String text = "abc <head > def </ head > ghi";
System.out.println(text.replaceAll("\\s++(?=[^<>]*+>)", ""));But when your tags contain attributes, you can't use the code above. But, you would have mentioned such an important piece of information in your original post, right? -
String question regarding "\"
i am trying to read in a CSV (coma separated value) file containing text like this
"2007/10/04","22:47:24","C:\test\tp2c266b.BAT","deleted","",""
"2007/10/04","22:48:06","C:\Program Files\Common Files\Symantec Shared\CCPD-LC\symlcrst.dll","changed","",""
"2007/10/04","22:48:19","C:\PROGRA~1\Symantec\LIVEUP~1\ludirloc.dat","changed","",""
Using a CSV parser from:
http://ostermiller.org/utils/CSV.html
This code is easy to use and looks just like the example shown.... However when i parse out the array and print it to the screen the output for the path name looks like this:
C:testtp2c266b.BAT
C:Program FilesCommon FilesSymantec SharedCCPD-LCsymlcrst.dll ---- no \ is there
i realize that the \ is an escape character but i need it, without it the directory listing is pointless.... please help have no idea what to do
How do i read in the \ from the file and keep the dang thing..... or replace it with a / anything is better then no indicator of directory structureCODE:
import com.Ostermiller.util.CSVParser;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.*;
import hansen.filespy;
import java.net.*;
public class EventReader {
public static void main(String[] args) throws Exception
java.net.InetAddress i = java.net.InetAddress.getLocalHost();
getMachineID ID = new getMachineID();
int machineid = ID.getIT(i.getHostName());
while(true)
runit(machineid);
try{Thread.sleep(10000);}catch(Exception e){}//sleep for 10sec
public static void runit(int machineid) throws Exception{
filespy spy = new filespy();
File f = new File("C:\\WINDOWS\\system32\\scl.csv");
//test code ---- usb key??
File[] roots = File.listRoots();
for ( File root : roots )
System.out.println( root );
//test code ---- end
if (f.exists()) {
CSVParser shredder = new CSVParser(new InputStreamReader(new FileInputStream("C:\\WINDOWS\\system32\\scl.csv")));
String[] t;
//remove header
String[] header; //------------------------------create string array to contain stings
header = shredder.getLine();
while ((t = shredder.getLine()) != null) {
System.out.println(t[1]); //date //-----------------------contains date
System.out.println(t[2]); //file //------------------------contains filepath ------ however it shows C:testprogram files instead of C:\test\program files
System.out.println(t[3]); //event //-----------contains event
System.out.println(t[4]); //empty line
spy.spy(t[1], t[2], t[3], "Non-System", machineid); //--------------sending to outside class for further parsing.... see code example from above for what im doing
shredder.close();
boolean f1 = new File( "C:\\WINDOWS\\system32\\scl.csv").delete();
if (!f1) {
System.out.println("failed to delete, file not there");
}//end if
else{System.out.println("no events");}
}
Maybe you are looking for
-
I have an application in CVI 5.0 that works. I am trying to export that so I can develop in MSVC. I need none of the UI provided in CVI, all I need are the simple FieldPoint commands provided in FieldPoint.obj. I have been stumped on this for weeks.
-
How to keep all visited sites from opening a new tab
No matter what I do, everything I click opens in a new tab., even if I am already on a tab I want it to replace. I can't find the setting to change this. I'd like to be able to do a CTRL--click if I want a new tab. It's annoying ending up with 30 tab
-
Can I bind multiple field values to a single field?
Here's the scenario: I have a form with 2 pages. On the first page, there are three fields for a person's first, middle, and last name. On the second page, there's a field that just says "Name". I want the user to fill out the first, middle and l
-
PowerBook won't stay closed!
My girlfriend's 12" PowerBook G4 will not stay closed. There is nothing wrong with the latch - the latch activates just fine and keeps the lid closed to the unit. However, it doesn't close enough - the screen will remain on and the unit will not go t
-
Adobe Design & Web Premium CS6 - Student - no Acrobat Pro installed
I purchased and installed Adobe Design & Web Premium CS6 - Student Version. The box and the Adobe site list Acrobat Pro included. But in reviewing the Creative Cloud, it lists Acrobat Pro as a Trial. I do have Acrobat Standard already installed. Is t