Hello,
I posted something about this a couple weeks ago and was pointed into the right direction, but lack of time with school and other projects at work, i haven't been able to sit down and figure out how to accomplish this task and the code that i need to do it.
Here is my situation.
I have been asked to attempt to develop code that will alphabetize parameters after the input has been broken up by this code(which was given to me)..... - int questionPos = inUrl.indexOf("?");
-
if (questionPos >= 0) {
-
StringBuffer sb = new StringBuffer(inUrl.substring(0, questionPos + 1));
-
-
StringTokenizer tokenizer = new StringTokenizer(inUrl.substring(questionPos + 1), "&", true);
-
-
while (tokenizer.hasMoreTokens()) {
-
String key = tokenizer.nextToken();
-
}
-
-
}
In my searching and suggestions I have received, doing this could be done by
Arrays.sort()
or
Collections.sort()
My issue is I do not know where/how to begin developing code for this. I just looked at Java/Java script for the 1st time a couple weeks ago, so I am completely clueless.
Here is an example of the input - Ex. input: <a href="/ffw/funds/divcapgains.do?year=2007&orderby=data_1&orderkey=DESC">Federated Fund Name</a>
If someone could help me develop code for this so that i can begin to get my feet wet and have something to build off of i would greatly appreciate it.
9 1741
Heya, Stang.
Changed thread title to better describe the problem (did you know that threads whose titles that do not follow the Posting Guidelines actually get FEWER responses?).
I just looked at Java/Java script for the 1st time a couple weeks ago, so I am completely clueless.
Clue: Those are two different languages and this forum doesn't deal with the one you're being asked to use.
Clue: Those are two different languages and this forum doesn't deal with the one you're being asked to use.
Moved to the Java forum where it belongs.
I have been asked to attempt to develop code that will alphabetize parameters after the input has been broken up by this code(which was given to me)..... - int questionPos = inUrl.indexOf("?");
-
if (questionPos >= 0) {
-
StringBuffer sb = new StringBuffer(inUrl.substring(0, questionPos + 1));
-
-
StringTokenizer tokenizer = new StringTokenizer(inUrl.substring(questionPos + 1), "&", true);
-
-
while (tokenizer.hasMoreTokens()) {
-
String key = tokenizer.nextToken();
-
}
-
-
}
In my searching and suggestions I have received, doing this could be done by
Arrays.sort()
or
Collections.sort()
My issue is I do not know where/how to begin developing code for this. I just looked at Java/Java script for the 1st time a couple weeks ago, so I am completely clueless.
Here is an example of the input - Ex. input: <a href="/ffw/funds/divcapgains.do?year=2007&orderby=data_1&orderkey=DESC">Federated Fund Name</a>
OK, first of all you will need a main method.
Your basic class will look like this: -
public class AlphabetizeParameters
-
{
-
public static void main(String[] args)
-
{
-
-
}
-
}
-
Into that, you insert the code, which you were given: -
import java.util.*;
-
-
public class AlphabetizeParameters
-
{
-
public static void main(String[] args)
-
{
-
int questionPos = inUrl.indexOf("?");
-
if (questionPos >= 0)
-
{
-
StringBuffer sb = new StringBuffer(inUrl.substring(0, questionPos + 1));
-
StringTokenizer tokenizer = new StringTokenizer(inUrl.substring(questionPos + 1), "&", true);
-
sorted = new String[tokenizer.countTokens()/2+1];
-
while (tokenizer.hasMoreTokens())
-
{
-
String key = tokenizer.nextToken();
-
}
-
}
-
}
-
}
-
I don't know, how the URL should be given to the function, but let's just assume, that it's given to the program as an arguemnt (so when you call it, it's something like "java AlphabetizeParameters /ffw/funds/divcapgains.do?year=2007&orderby=data_1&orderkey=D ESC"). Now you can access that as args[0].
You will need an Array (or whatever Container you want to use) to put the parameters into, so create one: -
String[] parameters;
-
...
-
parameters = new String[amountOfParameters];
-
Then you have to put the parameters into the Array ([i]parameters = whateverStringItShouldBe;).
As soon as you've done that, you can sort your Array with Arrays.sort(parameters);
One last hint: You can't display an array of Strings with System.out.println(parameters);, however you can do this: -
for(int i=0;i<parameters.length();i++)
-
System.out.println(parameters[i]);
-
OK, first of all you will need a main method.
Your basic class will look like this: -
public class AlphabetizeParameters
-
{
-
public static void main(String[] args)
-
{
-
-
}
-
}
-
Into that, you insert the code, which you were given: -
import java.util.*;
-
-
public class AlphabetizeParameters
-
{
-
public static void main(String[] args)
-
{
-
int questionPos = inUrl.indexOf("?");
-
if (questionPos >= 0)
-
{
-
StringBuffer sb = new StringBuffer(inUrl.substring(0, questionPos + 1));
-
StringTokenizer tokenizer = new StringTokenizer(inUrl.substring(questionPos + 1), "&", true);
-
sorted = new String[tokenizer.countTokens()/2+1];
-
while (tokenizer.hasMoreTokens())
-
{
-
String key = tokenizer.nextToken();
-
}
-
}
-
}
-
}
-
I don't know, how the URL should be given to the function, but let's just assume, that it's given to the program as an arguemnt (so when you call it, it's something like "java AlphabetizeParameters /ffw/funds/divcapgains.do?year=2007&orderby=data_1&orderkey=D ESC"). Now you can access that as args[0].
You will need an Array (or whatever Container you want to use) to put the parameters into, so create one: -
String[] parameters;
-
...
-
parameters = new String[amountOfParameters];
-
Then you have to put the parameters into the Array ([i]parameters = whateverStringItShouldBe;).
As soon as you've done that, you can sort your Array with Arrays.sort(parameters);
One last hint: You can't display an array of Strings with System.out.println(parameters);, however you can do this: -
for(int i=0;i<parameters.length();i++)
-
System.out.println(parameters[i]);
-
Thank you very much!
You will need an Array (or whatever Container you want to use) to put the parameters into, so create one: -
String[] parameters;
-
...
-
parameters = new String[amountOfParameters];
-
Then you have to put the parameters into the Array ([i]parameters = whateverStringItShouldBe;).
As soon as you've done that, you can sort your Array with Arrays.sort(parameters);
One last hint: You can't display an array of Strings with System.out.println(parameters);, however you can do this: -
for(int i=0;i<parameters.length();i++)
-
System.out.println(parameters[i]);
-
nepomuk,
First thank you very much for helping me. I apologize for my ignorance and lack of knowledge with Java. In the section above I would like to use an Array/ArrayList to do the sorting. This is now where i am getting confused, I follow what you are saying, but do to my lack of knowledge in this area. -
String[] parameters;
-
...
-
parameters = new String[amountOfParameters];
-
I'm not sure what the above code should be doing, and what i need to add into the (...) part?
You can display an array of Strings (or any other objects) using
See the details in the docs for the Arrays class.
nepomuk,
First thank you very much for helping me. I apologize for my ignorance and lack of knowledge with Java. In the section above I would like to use an Array/ArrayList to do the sorting. This is now where i am getting confused, I follow what you are saying, but do to my lack of knowledge in this area. -
String[] parameters;
-
...
-
parameters = new String[amountOfParameters];
-
I'm not sure what the above code should be doing, and what i need to add into the (...) part?
The first line ( String[] parameters;) defines an Array of Strings. At this point, the Array is not existent yet.
The last line ( parameters = new String[amountOfParameters];) actually creates the Array. The Strings however still must be defined.
Inbetween both lines you have to find out, how many Elements (Strings) the Array will have.
After that, you'll have to give the Elements of the Array values.
You can display an array of Strings (or any other objects) using
See the details in the docs for the Arrays class.
That is very usefull, thank you!
Thanks again for all of your help!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Topher |
last post by:
Hi,
I have a slight problem in that I want to list all the entries in a
DBM file. I'm fine with sorting my the key, but I want to sort by one
of the variables in the value - I know how to do...
|
by: p0wer |
last post by:
Let's suppose I have this sample document:
<root>
<entry id="1"
<date>2003-08-03</date>
<param_1>5</param_1>
<param_2>10</param_2>
</entry>
<entry id="2">
...
|
by: Federico G. Babelis |
last post by:
Hi All:
I have this line of code, but the syntax check in VB.NET 2003 and also in
VB.NET 2005 Beta 2 shows as unknown:
Dim local4 As Byte
Fixed(local4 = AddressOf dest(offset))
...
|
by: Xah Lee |
last post by:
Sort a List
Xah Lee, 200510
In this page, we show how to sort a list in Python & Perl and also
discuss some math of sort.
To sort a list in Python, use the “sort” method. For example:
...
|
by: Dimitris Mandalidis |
last post by:
Hello all,
Suppose we have the following struct :
struct foo {
int a;
int b;
char *c;
}
And :
|
by: Guoqi Zheng |
last post by:
Sir,
The default paging of datagrid is somehow use too much resource, so I am
using Stored procedure for the paging. You can find my Stored procedure at
the end of this message.
It works...
|
by: Owen T. Soroke |
last post by:
Using VB.NET
I have a ListView with several columns.
Two columns contain integer values, while the remaining contain string
values.
I am confused as to how I would provide functionality to...
|
by: KevinADC |
last post by:
Introduction
This discussion of the sort function is targeted at beginners to perl coding. More experienced perl coders will find nothing new or useful. Sorting lists or arrays is a very common...
|
by: mmorrison93 |
last post by:
I've created my own custom gridview that derives from the
System.Web.UI.WebControls.GridView class and am trying to implement my
own sorting and paging mechanisms. The GridView class has two...
|
by: KevinADC |
last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |