Compare a String Array to get Higher value

Hi, I'm trying to figure out how can I create a method in which I can compare my array of String by getting the higher value. For example I have an array called faces[]. What I would like to say is that if 2 is less than 5, and so forth print "blahhhh". I would appreciate some ideas on which is the best way to do this. Thanks a lot. Here is the code so far. I'm working on checkWinner() method
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class WarCard extends JFrame implements ActionListener {
     private Card deck[];
     private int currentCard, value, winner;
     private JPanel buttonPanel, labelPanel, textFieldPanel;
     private JButton buttons[];
     private JLabel labels[];
     private JTextField textFields[];
     public WarCard()
          super( "War! " );
          String faces[] = { "Ace", "Deuce", "Three", "Four", "Five", "Six",
               "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
          String suits[] = { "Hearts", "Diamonds", "Clubs", "Spades" };
          deck = new Card[ 52 ];
          currentCard = -1;
          //populate deck
          for ( int count = 0 ; count < deck.length; count++ )
               deck[ count ] = new Card( faces[ count % 13], suits[ count / 13 ] );
          // get content pane and create layout
          Container container = getContentPane();
          // create label grid
          labels = new JLabel[3];
               labels[ 0 ] = new JLabel( "Player 1: ");
               labels[ 1 ] = new JLabel( "Player 2: ");
               labels[ 2 ] = new JLabel( "Shuffle cards to begin" );
          labelPanel = new JPanel();
          labelPanel.setLayout( new GridLayout( 3, labels.length ) );
          for ( int count = 0; count < labels.length; count++) {
               labelPanel.add( labels[ count ] );
          }// end for loop
          container.add( labelPanel, BorderLayout.WEST );
          // create text field grid
          textFields = new JTextField[ 3 ];
               textFields[ 0 ] = new JTextField( 20 );
               textFields[ 1 ] = new JTextField( 20 );
               textFields[ 2 ] = new JTextField( 20 );
          textFieldPanel = new JPanel();
          textFieldPanel.setLayout( new GridLayout( 3, textFields.length ) );
          for ( int count = 0; count < textFields.length; count++) {
               textFields[ count ].setEditable( false );
               textFieldPanel.add( textFields[ count ] );
          }// end for loop
          container.add( textFieldPanel, BorderLayout.EAST );     
          // create button grid          
          buttons = new JButton[ 3 ];
               buttons[ 0 ] = new JButton( "Deal" );
               buttons[ 1 ] = new JButton( "Shuffle" );
               buttons[ 2 ] = new JButton( "Exit" );
          buttonPanel = new JPanel();
          buttonPanel.setLayout( new GridLayout( 1, buttons.length ) );
          for ( int count = 0; count < buttons.length; count++) {
               buttons[ count ].addActionListener( this );
               buttons[ 0 ].setEnabled( false );
               buttonPanel.add( buttons[ count ] );
          }// end for loop
          container.add( buttonPanel, BorderLayout.SOUTH );
          setSize( 425, 150 );
          setVisible( true );
    private void checkWinner()
        int i = 0;
        for( i=0; i < 13; i++ ){
         if ( s[ 0 ].equals("2 of Spades") & s[ 1 ]!="2 of Spades" ){
                txtGame[ 2 ].setText( " You Win " );
          else{
               txtGame[ 2 ].setText( " Compuer Win" );
     public static void main( String agrs[] )
          WarCard application = new WarCard();
          application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
     public void actionPerformed( ActionEvent event)
          String testString = "";
          for ( int count = 0; count < buttons.length; count++) {
               if ( event.getSource() == buttons[ 0 ] ) {
                    Card dealt1 = dealPlayer1();
                    Card dealt2 = dealPlayer1();
                    if ( dealt1 != null || dealt2 != null ) {
                         textFields[ 0 ].setText( dealt1.toString() );
                         textFields[ 1 ].setText( dealt2.toString() );
                         labels[ 2 ].setText( "# of Cards : " + currentCard);
                    else {
                         textFields[ 2 ].setText( "All Cards Dealt" );
                         labels[ 2 ].setText( "Shuffle Cards to continue" );
               else if ( event.getSource() == buttons[ 1 ] ) {
                    shuffle();
                    textFields[ 0 ].setText( " " );
                    textFields[ 1 ].setText( " " );
                    labels[ 2 ].setText( "Shuffled!");
               else if ( event.getSource() == buttons[ 2 ] ) {
                    System.exit( 0 );
          }// end for loop
     }// end method actionPerformed
          private void shuffle()
          currentCard = -1;
          for ( int first = 0; first < deck.length; first++ ) {
               int second = ( int ) ( Math.random() * 52 );
               Card temp = deck[ first ];
               deck[ first ] = deck[ second ];
               deck[ second ]= temp;
          buttons[ 0 ].setEnabled( true );
     private Card dealPlayer1()
          if ( ++currentCard < deck.length )
               return deck[ currentCard ];
          else {
               buttons[ 0 ].setEnabled( false );
               return null;
}// end of WarCard
class Card{
     private String face;
     private String suit;
     public Card( String cardFace, String cardSuit )
          face = cardFace;
          suit = cardSuit;
     public String toString()
          return face + " of " + suit;
     }// end toString
}// end class WarCard

assign an int value to the card and use < == >

Similar Messages

  • Insane object error(The string control not getting any values)

    In LabVIEW 8.2 i am using the string control to get the text from the users, and initially there was no problem at the time of development it works perfectly, after building the installer,
    these string controls are not getting any string input, it seems like a disabled one, but actually it was not disabled, when we try to click over that through the mouse,
     that text inputting cursor was not blinking over there,I screen looks as below, some error messages are thrown from the LabVIEW like insane object error, even
    now there was the same problem in the source code itself, what to do rectify this. Only this part generates error all other remaining screen panels are working perfectly.

    This kind of problem can be a pain to locate. This often occurs when the wiring to or from a control or indicator is bery long, convoluted and hidden inside of structures or behind things. So first, you need to identify which VI specifically is generating the error by individually saving VIs and subVIs until you find the one that is generating the error. Now try and remember the last time that VI saved without a problem and what edits you made since then. Places where I have had this occur was when I drag-copied a control and a couple VIs into a small structure. Sometimes the wires would seem to conect up properly, but when I tried to save the VI I got this error. The solution was to disconnect all the wires associated with the VIs I had copied and rewire them.
    Also, can you post the VI that is doing it? Shouldn't need the subVIs for this...
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Just comparing one string how to get the node?

    hi group,
    I get the string value like this:
    String listselvalue = getJList1().getSelectedValue().toString();
    Just i am comparing this with particular node.(which is in tree) like this:
    TreePath path = getmy_tree().getPathForRow(1);
    DefaultMutableTreeNode selnode = (DefaultMutableTreeNode)path.getLastPathComponent();
    Enumeration enum = selnode.children();
    while(enum.hasMoreElements())
         if(enum.nextElement().toString().equalsIgnoreCase(listselvalue))
              //here what trick I have to use to get that node.(if it matches)
    thank u...
    Shalinipriya.

    You need your node for both your test and your manipulation if the test is succesfull, so just keep a ref to your node before the test, and use that ref for both test and manipulation. Within your code, it should look like this:
    Enumeration elts = selnode.children();
    while ( elts.hasMoreElements() ) {
         // keep a ref to the current node,
         // so you can bith test its name
         // and manipulate it if it match you critiria
         Object currentNode = elts.nextElement();
         if ( currentNode.toString().equalsIgnoreCase( listValue ) ) {
              // here you have your currentNode object
              // that is a DefaultMutableTreeNode
              doNodeJob( currentNode );
    }

  • Trying to compare string array using equals not working

    Hi,
    im prolly being really dumb here, but i am trying to compare 2 string arrays using the following code:
    if(array.equals(copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}
    the trouble is that even though they do match i keep getting dont match, can anyone tell me why?

    try
    if (Arrays.equals(array, copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}

  • Getting index of a string array based on user selection in a comboBox

    I'm not really sure how to phrase my questions, but here goes.
    I have created a string array that holds the values of a ComboBox. Based on which selection the user makes in the comboBox, I need the program to then perform particular calcualtions (based on their selection). I have tried using an ItemListener, but that doesn't seem to work. I've also tried using the ActionListener connected to the ComboBox, again...without results. I'm not sure what I'm looking for exactly, but I know what I want it to do, I'm just not finding the right way to do it. Can anyone help me figure this out?

    Here is my entire code. I'm completely confused at where to put the ActionListener or how to make it do what I want. Right now I just have it set up to display a simple message in the displayArea, just so that I could see if it was working. I think once I figure out how to get the right index from the ComboBox array, then I'll be able to add the code I need to perform the calcualtions...it's just getting to that step that's not going so well! Any help is appreciated.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.DecimalFormat;
    import java.lang.String;
    public class MortCalcSR5 extends JFrame implements ActionListener
         int term = 0;
         double principal = 0;
         double rate = 0;
         double monthlyPyment = 0;
         double interest = 0;
         String[] loanChoices = {" ", "7 years @ 5.35%", "15 years @ 5.5%", "30 years @ 5.75%"};
         //create panel for input
         JPanel inputPanel = new JPanel();
              JLabel mortAmtLabel = new JLabel("Mortgage Amount $");
              JTextField mortAmtField = new JTextField(15);
              JLabel loanSelectionLabel = new JLabel("Loan Selection");
              JComboBox loanSelection = new JComboBox(loanChoices);
              JTextField loanSelected = new JTextField(15);
         //create button panel
         JPanel buttonPanel = new JPanel();
              JButton calcButton = new JButton("Calculate");
              JButton clearButton = new JButton("Clear");
              JButton exitButton = new JButton("Exit");
         //create panel for payment information
         JPanel paymentPanel = new JPanel();
              JLabel paymentLabel = new JLabel("Monthly Payment $");
              JTextField paymentField = new JTextField(15);
         //create panel for text box information
         JPanel textPanel = new JPanel();
              JLabel numPaymentLabel = new JLabel("Payment #");
              JLabel balLabel = new JLabel("Balance");
              JLabel ytdPrincLabel = new JLabel("Principal");
              JLabel ytdIntLabel = new JLabel("Interest");
         //create payment for display area
         JPanel displayPanel = new JPanel(new FlowLayout());
              JTextArea displayArea = new JTextArea(10,30);
              JScrollPane scroll = new JScrollPane(displayArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
         public MortCalcSR5()
              //set size of GUI display
              setSize(400,450);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              Container pane = getContentPane();
              JScrollPane scroll = new JScrollPane (displayArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
              FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
              pane.setLayout(layout);
              //add components to the inputPanel
              GridLayout layout2 = new GridLayout(4,1);
              inputPanel.setLayout(layout2);
              inputPanel.add(mortAmtLabel);
              inputPanel.add(mortAmtField);
              mortAmtField.setText(" ");
              inputPanel.add(loanSelectionLabel);
              inputPanel.add(loanSelection);
              loanSelection.addActionListener(this);
              pane.add(inputPanel);
              //add components to buttonPanel
              FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER, 10, 10);
              buttonPanel.setLayout(layout3);
              buttonPanel.add(calcButton);
              buttonPanel.add(clearButton);
              buttonPanel.add(exitButton);
              pane.add(buttonPanel);
              //add listeners to buttons
              calcButton.addActionListener(this);
              clearButton.addActionListener(this);
              exitButton.addActionListener(this);
              //add components to outputPanel
              FlowLayout layout4 = new FlowLayout(FlowLayout.LEFT, 10,10);
              paymentPanel.setLayout(layout4);
              paymentPanel.add(paymentLabel);
              paymentPanel.add(paymentField);
              pane.add(paymentPanel);
              //add components to textPanel
              FlowLayout layout5 = new FlowLayout(FlowLayout.LEFT, 10,10);
              textPanel.setLayout(layout5);
              textPanel.add(balLabel);
              textPanel.add(ytdPrincLabel);
              textPanel.add(ytdIntLabel);
              pane.add(textPanel);
              //add components to displayPanel
              FlowLayout layout6 = new FlowLayout(FlowLayout.CENTER,10,10);
              displayPanel.setLayout(layout6);
              displayPanel.add(scroll);
              pane.add(displayPanel);
              setContentPane(pane);
              setVisible(true);
         public void actionPerformed(ActionEvent event)
              String fs = (String)loanSelection.getSelectedItem();
              if (fs.equals("7 years @ 5.35%"))          {
                   displayArea.setText("yay");
              else
                   displayArea.setText("blah");
              JButton command = (JButton)event.getSource();
              if(command==calcButton)  //calculate button clicked - run payment event
                   Payment();
              if(command==clearButton) //clear button clicked - clear all fields
                   mortAmtField.setText(null);
                   paymentField.setText(null);
                   displayArea.setText(null);
                   loanSelected.setText(null);  //hidden text field still needs to be cleared
                   //loanChoices = null;
              if(command==exitButton)  //exit button clicked - exit program
                   System.exit(0);
         public void Payment()
              //perform the calculations
    //          int mortAmt = Integer.parseInt(mortAmtField.getText());
         //     double loanSelect = Double.parseDouble((String)loanSelected.getText());
              displayArea.append("Calcualations performed!");
         public static void main(String[] args)
              new MortCalcSR5();
    /*/calculations
         int mortAmt = Integer.parseInt(mortAmtField.getText());  //get text user entered in mortAmt field - parse it from a string to integer
         int loanTerm = Integer.parseInt(loanTermField.getText());  //get text user entered in loanTerm field - parse it from a string to integer
         double interestRate = Double.parseDouble(interestRateField.getText());  //get text user entered in interestRate field - parse it from a string to double
         int moTerm = (loanTerm*12);  //calculate monthly loan term
         double moInterest = ((interestRate/100)/12);  //calculate monthly interest rate
         double payment = mortAmt*(moInterest/(1-Math.pow(1/(1+moInterest), moTerm)));  //calculate monthly payment amount
         valid = true;  //number format is accepted
         paymentField.setText(Double.toString(payment));  //display output
    */

  • Problems with string arrays

    Previous task was:
    Write a class "QuestionAnalyser" which has a method "turnAnswerToScore". This method takes a String parameter and returns an int. The int returned depends upon the parameter:
    parameter score
    "A" 1
    "B" 2
    "C" 3
    other 0
    Alright, here's the recent task:
    Write another method "turnAnswersToScore". This method takes an array of Strings as a parameter, works out the numerical score for each array entry, and adds the scores up, returning the total.
    That's my code:
    class QuestionAnalyser{
    public static int Score;
    public String[] Answer;
    public static void main(String[] args) {}
         public int turnAnswerToScore(String[] Answer)
    for (int i = 0; i < Answer.length;i++) {
    if (Answer.equals("A")) {
    Score = Score + 1; }
    else if (Answer[i].equals("B")) {
    Score = Score + 2;}
    else if (Answer[i].equals("C")) {
    Score = Score + 3;}
    else {
    Score = Score + 0;}
    return Score;
    this is the error message I get:
    The results of trying to compile your submission and run it against a set of test data was as follows:
    ----------Compilation output--------------------------------------
    javac QATest2.java
    QATest2.java:15: cannot resolve symbol
    symbol : method turnAnswersToScore (java.lang.String[])
    location: class QuestionAnalyser
    if(qa.turnAnswersToScore(task)!=total){
    ^
    What went wrong?
    Suggestions would be greatly appreciated!

    If I declare int score in the method i get this message
    The results of trying to compile your submission and run it against a set of test data was as follows:
    ----------Compilation output--------------------------------------
    javac QATest2.java
    ./QuestionAnalyser.java:20: variable score might not have been initialized
    score++; }
    ^
    ./QuestionAnalyser.java:23: variable score might not have been initialized
    score++;
    ^
    ./QuestionAnalyser.java:27: variable score might not have been initialized
    score++;
    ^
    ./QuestionAnalyser.java:34: variable score might not have been initialized
    return score;
    ^
    4 errors
    ----------Sorry expected answer was-------------------------------
    The method turnAnswersToScore is working OK - well done!
    ----------Your answer however was---------------------------------
    Exception in thread "main" java.lang.NoClassDefFoundError: QuestionAnalyser
         at QATest2.main(QATest2.java:4)
    This is the message I get from the submission page, but trying to compile it I get the same messages.
    The code looks like this, then
    class QuestionAnalyser{
    String[] answer;
    public static void main(String[] args) {}
         public int turnAnswersToScore(String[] answer)
    int score;
    for (int i = 0; i < answer.length; i++) {
    if (answer.equals("A")) {
    score++; }
    else if (answer[i].equals("B")) {
    score++;
    score++; }
    else if (answer[i].equals("C")) {
    score++;
    score++;
    score++; }
    else {}
    return score;
    When I leave 'public int score;' where it was before (right after the class declaration below the declaration of the string array) I get this but it compiles normally.
    The results of trying to compile your submission and run it against a set of test data was as follows:
    ----------Compilation output--------------------------------------
    javac QATest2.java
    ----------Sorry expected answer was-------------------------------
    The method turnAnswersToScore is working OK - well done!
    ----------Your answer however was---------------------------------
    wrong answer in turnAnswersToScore for
    BDCAADDCA
    Alright, even university students need to sleep :-)
    Good night.

  • How can I get all the values of a String array profile property using javascript?

    I am trying to build functionality into our site that records all products added to the basket against a user's profile.
    I have so far been able to store the product codes against the profile as a property using Ajax:
           var dataString = ":formid=addProduct&:formstart=/apps/thread/templates/page_product/jcr:content/par/produc t/formstart&:redirect=/content/thread/en/user/cart.html&productId=151515:profile="+profile ;
                         $.ajax({ 
                type: "POST", 
                url: "/content/women/evening/dresses/l-k-bennett-davinadress.html", 
                data: dataString, 
                success: function(data) { 
    In this example I have hardcoded a product ID of 151515.
    In order to save the property as a multi string field you simply replace &productId=151515 with &productId=151515&productId=131313&productId=141414 or as many extra values as you want to build into that string. This stores a productId property against a user profile.
    The issue comes from calling that data back. Using var value = CQ_Analytics.ProfileDataMgr.getProperty("productId") I can get the first value of this array (or the single value if only one is stored).
    However there does not seem to be a way to get any of the other stored values in the array using getProperty. Does anyone know how I can achieve this?

    Hi,
    Don't think that's possible. Even if it were, you wouldn't be able to use/display BOOLEAN type in SQL.
    If you just aim to see what they are, you could do something like this
    select text
      from all_source
    where owner = 'SYS'
       and name = 'DBMS_DB_VERSION'
       and type = 'PACKAGE';Or even
    select dbms_metadata.get_ddl('PACKAGE', 'DBMS_DB_VERSION', 'SYS') from dual;My version is:
    SQL> select * from v$version where rownum = 1;
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    1 row selectedIn 11g you also have [PL/SCOPE|http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_plscope.htm#ADFNS02203] which might help you even more.
    Regards
    Peter

  • Get numerical values from 2D array of string

    Hello! 
    I start by saying that I have a base knowledge of LabView. I'm using LabView 2011. I'm doing some communications test via Can-Bus protocol. As you can see in pictures of the block diagram and of the front panel that I've attached I'm using "Transmit Receive same Port" LabView example. It works very good but I would need to insert the 8 data bytes that I receive from the server in 8 different numerical variables so that I could use them to make some operations. How can I get numerical values from the 2D array of string that I attached? 
    Every example that you can provide is important! 
    Thank you very much! 
    Attachments:
    1.jpg ‏69 KB
    2.jpg ‏149 KB

    Hi martiflix,
    ehm: to unbundle data from a cluster I would use the function Unbundle(ByName)…
    When you are new to LabVIEW you should take all the FREE online resources offered by NI on their website!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How to get the values of an Array using JSP Tags

    Hey guys,
    I need some help. I've splited a String using
    fn:split(String, delim) where String = "1,2,3,4" and delim is ,
    This method returns an Array of splited Strings. how do i get the values from this array using jsp tags. I don't wanna put java code to achive that.
    Any help would be highly appreciated
    Thanks

    The JSTL forEach tag.
    In fact if all you want to do is iterate over the comma separated list, the forEach tag supports that without having to use the split function.
    <c:set var="list" value="1,2,3,4"/>
    <c:forEach var="num" items="${list}">
      <c:out value="${num}"/>
    </c:forEach>The c:forTokens method will let you do this with delimiters other than a comma, but the forEach tag works well just with the comma-delimited string.

  • Compare two strings in an array

    Hello!
    Please feel free to give me hints, but do not give me any code.
    Ok, here is what I am trying to do, I whant to compare my input string whith strings allready stored in the array. If my input string equals any of the allready excisting strings, a error wil show upp, otherwise store the new string in next avalibal position. I do not seem to get the method right for comparing the strings. here is the method I have written so far, please take a look and give me a hint, but no code. :)
    //Check if a user already excists     
    public void compareNames (People in_array [], String in_name) {
              for (int i=0; i<value.peopleCount; i++) {
                   if (in_name.equals(in_array.getPeople())) {
                   System.out.print("The user already excist, please chose another name");
    }value.peopleCount is an global count value for people arays.
    getPeople get the name from the people class.
    Martin                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    A couple notes here.
    The name compareNames() is misleading if it is going to do what you described. A comparison will generally not have side-effects like outputting error messages to the console or adding new items to an array. It would be better if you called the method addIfNew(), and returned a boolean indicating whether the name was new or not. The caller would then be responsible for displaying an error message if the method returned false.
    I also suggest you use a List such as ArrayList instead of an array, otherwise you will have to resize and copy your array every time you add something to it that exceeds the array size, and will allow you to do away with the global peopleCount.

  • Getting char values from a string problem

    Hi,
    Here's an example of what I'm trying to do:
    boolean loopSwitch = true;
    while (loopSwitch)
         String orderDecider = JOptionPane.showInputDialog (null, "Would you like your numbers to be ordered in   ascending or descending order(A/D)",      "Order decision", JOptionPane.QUESTION_MESSAGE);
         if (orderDecider == A)
         loopSwitch = false;
         }I basically want the user to input either a/A/d/D and to get the char values from the string so I can use them in an if statement.
    Basically, I wanna parse the string into a char.
    Is this possible?
    Thanks.
    Edited by: xcd on Oct 16, 2009 8:38 AM

    Why not just use the String.equals() method to compare a String to a String?
    But if you must, you can use the String.charAt() method to return a char at a particular location in the String.
    Note: char literals need to be surrounded by single quotes ('A') and String literals need to be surrounded by double quotes ("A").

  • Getting null values from array

    I have set up an array which is supposed to take the values of a recordset. Only problem is when I display them on the page, I get a list of 'null' instead of the data.
    I'm trying to list first and last name (fname_ul & lname_ul in DB)
    Here's my code:
    <% // Here I'm getting the amt of rows returned
    int count=1;
    while(rs.next()) {
    count++;
    %>
    <%
    int k = count;
    int i = 0;
    String[] fname = new String[k]; // here i'm trying to initialize the string arrays;
    String[] lname = new String[k];
    while (rs.next()) {
    fname[i] = rs.getString("fname_ul"); // here i'm trying to put data into the array;
    lname[i] = rs.getString("lname_ul");
    i++;
    %>
    <table>
    <% for (i=0; i < k; i++) { %>  // and finally here i'm trying to display the array;
    <tr>
         <td><%=fname%></td>
         <td><%=lname[i]%></td>
         <td><%=i%></td> // just something to make sure the rows are counting.
    </tr>
    <% } %>
    </table>
    my result is like this:
    null null 0
    null null 1
    null null 18 // this is correct in that there are 19 rows in the resultset.
    So, why isn't the data from the recordset going into the array??? Thanks for any help out there. Oh, those comments up there, they're not in the actual code, just to explain here.

    I have set up an array which is supposed to take the
    values of a recordset. Only problem is when I display
    them on the page, I get a list of 'null' instead of
    the data.
    I'm trying to list first and last name (fname_ul &
    lname_ul in DB)
    Here's my code:
    <% // Here I'm getting the amt of rows returned
    int count=1;
    while(rs.next()) {
    count++;
    %>
    <%
    int k = count;
    int i = 0;
    String[] fname = new String[k]; // here i'm trying
    to initialize the string arrays;
    String[] lname = new String[k];
    while (rs.next()) {
    fname[i] = rs.getString("fname_ul"); // here i'm
    trying to put data into the array;
    lname[i] = rs.getString("lname_ul");
    i++;
    %>Well, in the first while-loop, you already loop through all the result set, so in the second while-loop, all you get is a null value.
    Also, the way you put the data into the array is not right. I didn't see any array indices. Instead of using arrays, you can consider using Vector, so you don't need to know the number of rows in advance.

  • How to get the Values i need from a String???

    hi i need some help on my program,
    I have a Server that actually sent some data to my Client.
    The data consist of some messages and intergers . The whole piece of data is stores as a String message.
    ARRAY 'Monitor Chart' 2 5
    'Total OverFlow' 'Queued' 'Completed' 'Host Resets' 'Errors'''
    0.0 1.0 2.0 3.0 4.0
    'Series1' 11.0 0.6 8.6 11.5 6.6
    'Series2' 12.8 6.7 21.6 11.1 30.0Inside the Client i need to get the values out to showed on my textfields
    Example :
    Tf1 = 11.0
    Tf2 = 0.6
    Tf3 = 8.6
    Tf4 = 11.5
    Tf5 = 6.6
    Question: How to i get the values out from the String???

    using the split() method. i am able to split everything now
    so it appear somthing like this :
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class testing{
         String d1 =     "ARRAY 'Monitor Chart' 1 5";
         String d2 = "'Total OverFlow' 'Queued' 'Completed' 'Host Resets' 'Errors'";
         String d3 = "'' 0.0 1.0 2.0 3.0 4.0 ";
         String d4 = "'Series1' 11.0 0.6 8.6 11.5 6.6 ";
         String d5 = "'Series2' 12.8 6.7 21.6 11.1 30.0 ";
         String data = d1 + d2 + d3 + d4 + d5;     
         public testing(){
              System.out.println(data);
              String[] result = data.split("\\s");
              for(int x=0;x<result.length;x++)
              System.out.println(result[x]);
         public static void main (String args[])throws IOException{
            testing Application = new testing();
    }ARRAY
    'Monitor
    Chart'
    2
    5
    'Total OverFlow'
    'Queued'
    'Completed'
    'Host Resets'
    'Errors'''
    0.0
    1.0
    2.0
    3.0
    4.0
    'Series1'
    11.0
    0.6
    8.6
    11.5
    6.6
    'Series2'
    12.8
    6.7
    21.6
    11.1
    30.0
    but how do i get the values out ??how do i noe it is which index or wad?
    11.0
    0.6
    8.6
    11.5
    6.6

  • How to get multiple values using HttpSession.getAttribute(java.lang.String)

    Hey Guys
    I'm trying to find a way to get multiple values using the following method
    HttpSession.getAttribute(java.lang.String)
    Here's the scenerio. Its a already written application and now i'm trying to make some changes. earlier in the jsp page a combo box was used and value was retrieved in the servlet using the getAttribute method of Session. Now I'm using a html multiple selection list and have to retrieve all the values selected in the list in the servlet. Can anyone please suggest me how to do that. HTTPRequest class has a method getParameterValues which will let me do that but i have to do is using HTTPSession.
    Thanks for your time to read this

    I'm not sure what you are trying to do. You can only use session.getAttribute to retrieve something that has already been stored in the session with a previous setAttribute. If you need to store multiple values under one attribute name using setAttribute, you can store an array, or an ArrayList or whatever type of Collection you want. The request.getParameterValues method is the only way you can retrieve form parameters than can have multiple values. If the servlet hasn't already processed these parameters and put them into the session for you, you have to use request.getParameterValues.

  • Getting the value of a child node in an array

    How do you get the value of a child node in an array titled "entries"?  I used to do this in AS2, and now I'm trying in AS3.  To top it off, I'm forced to use an XML format I'm unfamiliar with.  So I'm not sure how to access these nodes in AS3.  An example of the XML is;
       <Row>
        <Cell><Data ss:Type="String">Absorption Areas</Data></Cell>
        <Cell><Data ss:Type="String">Drain fields where left over liquid from the septic system soak into the ground.</Data></Cell>
       </Row>
    How would I access ether of the <Cell> rows?
    Thanks

    Given that you declared ss namespace (otherwise it will throw an error) you have two options:
    xml.Cell[0].Data - will output:
    Absorption Areas
    xml.Cell.Data will output:
    <Data ss:Type="String">Absorption Areas</Data>
    <Data ss:Type="String">Drain fields where left over liquid from the septic system soak into the ground.</Data>
    So, xml.Cell.Data[1] will output:
    Drain fields where left over liquid from the septic system soak into the ground.

Maybe you are looking for