how to store and retrive a set of values without using an
array
Answers were Sorted based on User's Feedback
I think U need this .......
/*****************************************************/
import java.util.*;
class TreeSetDemo {
public static void main(String args[]) {
// Create a tree set.
TreeSet<String> ts = new TreeSet<String>();
// Add elements to the tree set.
ts.add("C");
ts.add("A");
ts.add("B");
ts.add("E");
ts.add("F");
ts.add("D");
System.out.println(ts);
}
}
/******************************************************/
The output from this program is shown here:
[A, B, C, D, E, F]
/*******************************************************/
/********************************
************ AND ************
**********************************/
import java.util.*;
class HashSetDemo {
public static void main(String args[]) {
// Create a hash set.
HashSet<String> hs = new HashSet<String>();
// Add elements to the hash set.
hs.add("B");
hs.add("A");
hs.add("D");
hs.add("E");
hs.add("C");
hs.add("F");
System.out.println(hs);
}
}
/**************************************/
The following is the output from this program:
[D, A, F, C, B, E]
/****************************************/
Is This Answer Correct ? | 12 Yes | 6 No |
Answer / r.jude silvester
You can use any of Collections like Vector,ArrayList or HashSet etc.
Is This Answer Correct ? | 5 Yes | 2 No |
Answer / madhura
impotr java.util.*;
class store
{
public static void main(String args[])
{
Vector v=new Vector();
for(int i=0;i<10;i++)
{
v.addElement(i);
}
System.out.println("the elements in vector are"+v);
}}
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / r.jude silvester
You can use any of the Collections for eg.ArrayList
Is This Answer Correct ? | 0 Yes | 1 No |
import java.util.*;
import java.io.*;
public class Store
{
public static void main(String args[])
{
System.out.println
("enter number of elements to be stored");
Scanner cin=new Scanner(System.in);
int n=cin.nextInt();
Vector v=new Vector();
for(int i=0;i<n;i++)
{
v.addElement(i);
}
System.out.println("the elements in vector are"+v);
}}
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / kiran
please post the answer...
thanks and regards
kiran.y
Is This Answer Correct ? | 3 Yes | 7 No |
Answer / ashok kumar
using
BufferedReadered br=new BufferedReader(new InputStreamReader
(System.in));
while (br.readline)
System.out.println(br);
B
Is This Answer Correct ? | 1 Yes | 7 No |
write a program that will ask the user to enter a number n and display the product of all numbers from 1 to n.
How Can I Trace A Java Program . Please Give Me Step by Step Process
1+(2*3)+(4*5*6)+(7*8*9*10)+... specified input value
A game that has five levels of play has the score for each level stored in an array. You are to write a program that goes through that array and finds: a) the minimum score, and the level at which it occurred b) the maximum score, and the level at which it occurred c)the average score for all five levels The score data you must use for this program are as follows: Game Level Score 1 450 2 316 3 148 Stack implementations is mandatory.
what are the other loops except for for,while,do while and until?
I am trying to pass the string firstName from a Servlet called SampleServet. I am running this on eclipse and it tells me that "the value for annotation attribute must be a constant expression. I don't understand why it is giving me this error. @PersonAnnotation(name = SampleServlet.firstName) public class AnnotationClass{
How to create Date method to set the date in Ms Access
Is there any static classes are in java give some examples
In java, why do we set thread priority, when we know that there is no guarantee by which a thread should be execute?
Program to print map of India in java.
write a program that inputs two real numbers then exchanges their values.
write a program in java to find the moving average of all prime numbers between 2 and 100.